<template>
  <div class="page-container page-container-create">
    <div class="breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>营销中心</el-breadcrumb-item>
        <el-breadcrumb-item>通用促销</el-breadcrumb-item>
        <el-breadcrumb-item>创建单品X件优惠活动</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <p class="font22 mb20" v-if="promotionId && promotionId != '0'">编辑单品X件优惠活动</p>
    <p class="font22 mb20" v-else>创建单品X件优惠活动</p>
    <!-- 添加商品 -->
    <el-dialog :visible.sync="dialogVisibleTwo" title="添加商品" :close-on-click-modal="false">
      <div>
        <div>
          <el-form :inline="true" :model="productForm" ref="productForm" :size="size" :rules="productFormRules">
            <div class="col-sm-9">
              <el-form-item label="商品名称：" prop="chineseName" class="w178 mb30" label-width="112px">
                <el-input v-model="productForm.chineseName" auto-complete="off" clearable maxlength="80" placeholder="商品名称"></el-input>
              </el-form-item>
              <el-form-item label="商品编码：" prop="code" class="w178" >
                <el-input v-model="productForm.code" auto-complete="off" clearable maxlength="80" placeholder="商品编码"></el-input>
              </el-form-item>
              <el-form-item label="商品类目：" prop="categoryName" class="w178" >
                <el-input v-model="productForm.categoryName" auto-complete="off" clearable maxlength="80" placeholder="商品类目"></el-input>
              </el-form-item>
              <el-form-item label="所属商户：" prop="storeName" class="w178">
                <el-input v-model="productForm.storeName" auto-complete="off" clearable maxlength="80" placeholder="商户"></el-input>
              </el-form-item>
               <el-form-item label="商户Code：" prop="storeCode" class="w178">
                <el-input v-model="productForm.storeCode" auto-complete="off" clearable maxlength="80" placeholder="商户Code"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <el-row class="mb30 mt20 t_r">
            <el-button class="resetButton" icon="el-icon-refresh" size="mini" @click="resetProductForm()">重置</el-button>
            <el-button class="searchButton" size="mini" @click="productFormFind(1)" icon="el-icon-search">搜索</el-button>

            <!-- <el-button class="searchButton" size="mini" @click="addAllProduct()">全部添加</el-button> -->
          </el-row>
        </div>
        <div>
          <el-table
            :data="tableDataTwo"
            @selection-change="addSelectionChangeProduct"
            :header-cell-style="tableHeaderColor"
            ref="multipleTable"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            v-loading="tableDataTwoLoading"
            :size="size"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="code" label="商品编码" sortable align="center"></el-table-column>
            <el-table-column prop="chineseName" label="商品名称" align="center"></el-table-column>
            <el-table-column prop="goodsCategory" label="商品类目" align="center"></el-table-column>
            <el-table-column prop="storeName" label="所属商户" align="center"></el-table-column>
            <el-table-column prop="storeCode" label="商户Code" align="center"></el-table-column>
            <el-table-column prop="salePriceScope" label="原价（元）" align="center"></el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar t_r" v-if="tableDataTwo.length > 0">
            <el-pagination
              @size-change="producthandleSizeChange"
              @current-change="producthandleCurrentChange"
              :current-page="productForm.start"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="productForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="productListTotal"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button class="resetButton" :size="size" @click.native="dialogVisibleTwo = false">取消</el-button>
        <el-button
          :size="size"
          class="searchButton"
          @click.native="dialogVisibleTwo = false"
          @click="productTableData2Click"
          :loading="productEditLoading"
        >确定</el-button>
      </div>
    </el-dialog>
    <!--setp##-&#45;&#45;111end-->
    <!--审核弹框-->
    <el-dialog
      title="管理员备注"
      class="el-dialog-style"
      :visible.sync="dialogVisibleAdmin"
      :close-on-click-modal="false"
      @closed="handleClose"
    >
      <el-form
        :model="adminDataForm"
        label-width="100%"
        :size="size"
        ref="adminDataForm"
        :rules="adminDataFormRules"
        label-position="right"
        inline
      >
        <el-form-item prop="auditRemark" class="textarea">
          <el-input
            type="textarea"
            placeholder="请输入备注"
            v-model="adminDataForm.auditRemark"
            :rows="4"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer t_c">
        <el-button :size="size" class="cancelButton" @click.native="submitFormAdminNotPass" >不通过</el-button>
        <el-button :size="size" class="searchButton" @click.native="submitFormAdmin">通过</el-button>
      </div>
    </el-dialog>

    <!--工具栏-->
    <div class="toolbar">
      <div class="stepset" >
        <ul>
          <li :class="{'active':active>=1}"><span>1</span><p>设置促销规则</p></li>
          <!-- <li :class="{'active':active>=2}"><span>2</span><p>设置活动商家/店铺</p></li> -->
          <li :class="{'active':active>=3}"><span>2</span><p>设置活动商品</p></li>
          <li :class="{'active':active>=4}"><span>3</span><p>创建成功</p></li>
        </ul>
      </div>
      <div v-show="active==1" class="content create_stepOne createSet create_stepAlso">
        <el-form
          :inline="true"
          :model="filters"
          :rules="filtersRules"
          ref="filters"
          :label-position="labelPosition"
          label-width="140px"
        >
          <div>
            <div class="title">基本设置：</div>
            <div class="item">
              <el-row class="m_b30">
                <el-form-item label="活动名称：" prop="promName" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.promName"
                    placeholder="请输入3-60个字符之间"
                    maxlength="60"
                    minlength="3"
                    class="input" clearable
                  />
                </el-form-item>
              </el-row>

              <el-row class="m_b30">
                <el-form-item label="活动时间：" prop="promotionStartEndTime" class="wid t_r w450" label-width="140px">
                  <el-date-picker
                    v-model="filters.promotionStartEndTime"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    size="mini"
                    format="yyyy-MM-dd HH:mm:ss"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    :picker-options="timeCheck"
                  ></el-date-picker>
                </el-form-item>
              </el-row>

              <el-row class="m_b30">
                <el-form-item label="活动搜索词：" prop="searchKeyword" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.searchKeyword"
                    placeholder="多个搜索词可用数据逗号“,”隔开"
                    class="input" clearable
                  />
                </el-form-item>
              </el-row>

               <el-row class="m_b30">
                <el-form-item label="活动费用预算：" prop="budget" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.budget"
                    placeholder="请输入平台营销费用"
                    class="input" clearable
                    oninput="value=value.replace(/[^\d]/g,'')"
                  /><span>元</span>
                </el-form-item>
              </el-row>
              <el-row class="m_b30">
                <el-form-item label="预警比例：" prop="warningNum" class="wid t_r" label-width="140px">
                  <el-input
                    type="text"
                    v-model.trim="filters.warningNum"
                    placeholder="请输入预警比例"
                    class="input" clearable
                    oninput="value=value.replace(/[^\d]/g,'')"
                  /><span>%</span>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div>
            <div class="title">活动规则：</div>
            <div class="item">
              <el-row class="m_b30 labelAlignment">
                <el-form-item label="活动类型：" prop="frontPromType" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.frontPromType" @change="resetPromotionRule(0)">
                      <el-radio :label="12" border class="form-radio mr40 noMarginLeft radioAlignment">第X件Y折</el-radio>
                      <el-radio :label="13" border class="form-radio mr40 noMarginLeft radioAlignment">第X件Y元</el-radio>
                      <el-radio :label="14" border class="form-radio radioAlignment noMarginLeft">满X件Y折</el-radio>
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>

              <el-row class="m_b30  uptoadd labelAlignmentSpecial">
              <el-form-item label="是否叠加应用：" prop="overlayAppFlag" class="wid">
                <el-radio-group v-model="filters.overlayAppFlag">
                  <el-radio border :label="0" class="form-radio mr40 radioAlignmentSpecial noMarginLeft w315">否（超量：按最高层级享受优惠）</el-radio>
                  <el-radio border :label="1" class="form-radio radioAlignmentSpecial noMarginLeft w315" @change="resetPromotionRule(1)">是（倍量：每满一级优惠一次）</el-radio>
                </el-radio-group>
                <el-form-item
                  prop="overlayAppNum"
                  class="wid "
                  v-if="filters.overlayAppFlag == 1"
                >
                  <span class="cb">，上限</span>
                  <span v-if="filters.overlayAppFlag == 1"></span>
                  <el-input size="mini" v-model="filters.overlayAppNum" clearable class="w72 turnInlineBLock" maxlength="3"></el-input>
                  <span class="cb">次</span>
                </el-form-item>
              </el-form-item>
              </el-row>

              <el-row >
                <el-form-item label="优惠设置：" class="wid labelAlignment vt" prop="promotionRules">
                  <div class="disCountSet disCountSetTwo">
                    <el-table :data="filters.promotionRules" class="stepOne_table specialTable">
                      <el-table-column prop="couponSetindex" label="优惠阶梯" width="100">
                        <template slot-scope="scope">
                          <label>{{ scope.$index + 1 }}</label>
                        </template>
                      </el-table-column>
                      <el-table-column prop="content" label="优惠门槛" width="308">
                        <template slot-scope="scope" class="conditionValue">
                          <div class="flex">
                            <el-form-item
                              :prop="'promotionRules.' + scope.$index + '.conditionValue'"
                              :rules="filtersRules.conditionValue"
                              class="errorInfoAlignment"
                            >
                              <span class="disCountSetLabel" v-if="filters.frontPromType==12">第</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==13">第</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==14">满</span>
                              <el-input
                                v-model="scope.row.conditionValue"
                                placeholder="X"
                                :size="size"
                                clearable maxlength="10"
                              ></el-input>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==12">件, 打</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==13">件, 付</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==14">件, 打</span>
                            </el-form-item>
                            <el-form-item
                              :prop="'promotionRules.' + scope.$index + '.contentValue'"
                              :rules="filtersRules.contentValue"
                            >
                              <el-input
                                v-model="scope.row.contentValue"
                                :size="size"
                                placeholder="Y"
                                clearable maxlength="10"
                              ></el-input>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==12">折</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==13">元</span>
                              <span class="disCountSetLabel" v-if="filters.frontPromType==14">折</span>
                            </el-form-item>
                          </div>
                        </template>
                      </el-table-column>

                      <el-table-column prop="explain" label="优惠说明" width="250">
                        <template slot-scope="scope">
                          <label>
                            <span v-if="filters.frontPromType==12">第</span>
                            <span v-if="filters.frontPromType==13">第</span>
                            <span v-if="filters.frontPromType==14">满</span>
                            {{scope.row.conditionValue}}
                            <span
                              v-if="filters.frontPromType==12"
                            >件, 打</span>
                            <span v-if="filters.frontPromType==13">件, 付</span>
                            <span v-if="filters.frontPromType==14">件, 打</span>
                            {{scope.row.contentValue}}
                            <span
                              v-if="filters.frontPromType==12"
                            >折</span>
                            <span v-if="filters.frontPromType==13">元</span>
                            <span v-if="filters.frontPromType==14">折</span>
                            ;
                          </label>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作" width="100">
                        <template slot-scope="scope">
                          <el-button
                            v-if="filters.promotionRules.length>1"
                            size="mini"
                            type="text"
                            @click="removePromotionRuleSet(scope.$index, scope.row)"
                          >删除</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                    <el-button
                      v-if="filters.overlayAppFlag == 0"
                      size="mini"
                      class="searchButton"
                      @click="addPromotionRuleSet"
                      :disabled="filters.promotionRules.length > 4"
                    >新增优惠</el-button>
                  </div>
                </el-form-item>
              </el-row>

              <el-row class="labelAlignment">
                <el-form-item label="活动描述：" prop="description" class="wid">
                  <el-input
                    class="activityDesc remarks"
                    type="textarea"
                    :rows="2"
                    :placeholder="genDescriptionPlaceholder()"
                    v-model="filters.description"
                    clearable
                    maxlength="100"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label class="wid">
                  <div
                    class="desc color666"
                  >注：非必填字段，不填将显示系统默认文案（会存在某些促销类型无系统默认文案）。</div>
                  <div  class="desc color666">自定义输入活动规则描述描述后将显示在前台商品详情页、购物车和活动聚合页中。</div>
                  <div class="desc color666">活动聚合页显示规则为：“以下商品参加”+%促销活动名称%+“活动”，加购提醒显示规则为：“还差”+%X%+“元可享受”+%促销名称%+“活动”；请慎重填写。<a href=""></a></div>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div class="w100">
            <div class="title">交易规则：</div>
            <div class="item">

              <el-row class="m_b60 ways labelAlignment"  v-if="deptType != 3">
                <el-form-item label="是否分摊：" prop="costAllocationFlag" class="wid">
                  <el-row class="m_b52">
                    <el-radio-group v-model="filters.costAllocationFlag">
                      <el-radio :label="1" border class="form-radio mr40 radioAlignment noMarginLeft w138 t_l">是</el-radio>
                      <el-radio :label="0" border class="form-radio radioAlignment noMarginLeft w138 t_l">否</el-radio>
                    </el-radio-group>
                  </el-row>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div class="w100">
            <div class="title">参与条件：</div>
            <div class="item">

              <el-row class="m_b52 labelAlignment">
<!--                <el-form-item label="新老用户：" prop="proUserType" class="wid">-->
<!--                  <el-radio-group v-model="filters.proUserType">-->
<!--                    <el-radio-->
<!--                      class="m_r45 radioAlignment"-->
<!--                      v-for="city in proUserTypeRadios"-->
<!--                      :label="city.code"-->
<!--                      :key="city.code"-->
<!--                    >{{city.name}}</el-radio>-->
<!--                  </el-radio-group>-->
<!--                </el-form-item>-->
                <el-form-item label="新老用户：" prop="selectUserType" class="wid t_r" label-width="140px">
                  <div class="flex">
                    <div>
                    <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10" border :indeterminate="userTypeIsIndeterminate" v-model="userTypeCheckAll" @change="handleCheckAllUserTypeChange">全选</el-checkbox>
                    </div>
                    <div>

                    <el-checkbox-group v-model="selectUserType" @change="handleCheckedUserTypeChange">
                      <el-checkbox :label="1" :key="1" class="mr40 el-checkBox-padding noMarginLeft w130 t_l" border>新用户</el-checkbox>
                      <el-checkbox :label="2" :key="2" class="el-checkBox-padding noMarginLeft w130 t_l" border>老用户</el-checkbox>
                    </el-checkbox-group>
                    </div>
                  </div>
                </el-form-item>
              </el-row>
              <el-row class="m_b52 labelAlignment">
                <el-form-item label="会员类型：" prop="selectMemTypes" class="wid t_r" label-width="140px">
                  <div class="flex">
                    <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10" border :indeterminate="memTypeIsIndeterminate" v-model="memTypeCheckAll" @change="handleCheckAllMemTypeChange">全选</el-checkbox>
                    <el-checkbox-group v-model="selectMemTypes" @change="handleCheckedMemTypeChange">
                      <el-checkbox :label="1" :key="1" border class="mr40 el-checkBox-padding noMarginLeft">普通会员</el-checkbox>
                      <el-checkbox :label="2" :key="2" border class="el-checkBox-padding noMarginLeft">we2000</el-checkbox>
                      <el-checkbox :label="3" :key="3" border class="el-checkBox-padding noMarginLeft">分期会员</el-checkbox>
                    </el-checkbox-group>
                  </div>
                </el-form-item>
              </el-row>
               <el-row class="m_b52 labelAlignment">
                <el-form-item label="渠道入口：" prop="channelId" class="wid t_r" label-width="140px">
                  <div class="flex">
                    <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10" border
                                 :indeterminate="memChannelIsIndeterminate" v-model="memChannelCheckAll"
                                 @change="handleCheckAllMemChannelChange">全选
                    </el-checkbox>
                    <el-checkbox-group v-model="selectMemChannels" @change="handleCheckedMemChannelChange">
                      <el-checkbox class="mr40 el-checkBox-padding noMarginLeft w130 t_l mleft10" border
                                   :indeterminate="channelIdIsIndeterminate" v-model="channelIdCheckAll"
                                   @change="handleCheckAllChannelIdChange">全选
                      </el-checkbox>
                      <el-checkbox-group v-model="channelId" @change="handleCheckedChannelIdChange">
                        <el-checkbox :label="1" :key="1" border class="mr40 el-checkBox-padding noMarginLeft">企业微信
                        </el-checkbox>
                        <el-checkbox :label="2" :key="2" border class="mr40 el-checkBox-padding noMarginLeft">xxx
                        </el-checkbox>
                        <el-checkbox :label="3" :key="3" border class="mr40 el-checkBox-padding noMarginLeft">yyy
                        </el-checkbox>
                      </el-checkbox-group>
                    </el-checkbox-group>
                  </div>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="备注：" class="wid">
                  <el-input
                    type="textarea"
                    v-model="filters.remark"
                    @input="changeRemark($event)"
                    placeholder="请输入备注"
                    class="remarks h286"
                    clearable
                  ></el-input>
                   <!-- <quill-editor
                      class="remarks h286"
                      type="textarea"
                      v-model="filters.remark"
                      style="height: 300px;"
                      placeholder="请输入备注" clearable
                     ></quill-editor> -->
                </el-form-item>
              </el-row>
            </div>
          </div>
        </el-form>
      </div>

      <!-- <div class="tab-container tab-container-noPadding createSet" v-show="active==2">
        <el-tabs type="border-card">
          <el-tab-pane label="商家">
            <el-row class="search-button-fix t_r">
              <div class="w100 t_r">
                <div v-if="this.auth =='0'" >
                  <el-button
                    class="searchButton"
                    size="mini"
                    @click="searchMerchantFlag = !searchMerchantFlag"
                    icon="el-icon-search"
                  >搜索</el-button>
                  <el-button class="searchButton" size="mini" @click="querySupplierListForAdd()">添加商家</el-button>
                  <el-button  class="resetButton" size="mini" @click="delAllSelectedSuppliermerchantTableData2()">批量删除</el-button>
                </div>
              </div>
            </el-row>
            <div class="w100">
                <div v-if="searchMerchantFlag" class="f_r mb30">
                  <el-form
                    :inline="true"
                    :model="merchantSearchForm"
                    size="mini"
                    ref="merchantSearchForm"
                    :rules="merchantSearchFormRules"
                  >
                    <el-form-item label="商家编码：" prop="orgNumber" class="mr30">
                      <el-input v-model="merchantSearchForm.orgNumber" clearable maxlength="80" placeholder="商家编码"></el-input>
                    </el-form-item>
                    <el-form-item label="商家名称：" prop="merchantName">
                      <el-input v-model="merchantSearchForm.merchantName" clearable maxlength="80" placeholder="商家名称"></el-input>
                    </el-form-item>
                    <el-form-item label prop="mpName">
                      <el-button
                        class="resetButton"
                        size="mini"
                        @click="resetMerchantSearch()"
                      >重置</el-button>
                      <el-button class="resetButton" size="mini" @click="merchantSearch()">查询</el-button>
                    </el-form-item>
                  </el-form>
                </div>
            </div>
            <el-table
              :data="merchantTableData2"
              v-loading="merchantTableData2Loading"
              @selection-change="merchantTableData2selectionChange"
            >
              <el-table-column type="selection"></el-table-column>
              <el-table-column label="商家编号">
                <template slot-scope="scope">
                  <span>{{ scope.row.orgNumber}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="商家名称">
                <template slot-scope="scope">
                  <span>{{ scope.row.name}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="type" label="商家类型">
                <template slot-scope="scope">
                  <span v-if="scope.row.merchantType =='1'">自营商家</span>
                  <span v-if="scope.row.merchantType =='2'">第三方商户</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" v-if="this.auth =='0'">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    class="textButton"
                    @click="merchantTableData2delete(scope.row.id)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="toolbar t_r">
              <el-pagination
                layout="total, sizes, prev, pager, next, jumper"
                @current-change="mainMerchantRefreshPageRequest"
                :current-page="mainMerchantForm.pageNo"
                :page-size="mainMerchantForm.pageSize"
                :total="mainMerchantTableDataTatol"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="mainMerchantHandleSizeChange"
              ></el-pagination>
            </div>
          </el-tab-pane>

          <el-tab-pane label="店铺">
            <el-row class="search-button-fix t_r">

              <div class="w100 t_r">
                <div v-if="this.auth =='0'">
                  <el-button
                    class="searchButton"
                    size="mini"
                    @click="searchStoreFlag = !searchStoreFlag"
                    icon="el-icon-search"
                  >搜索</el-button>
                  <el-button class="searchButton" size="mini" @click="querySupplierListForAdd2()">添加店铺</el-button>
                  <el-button
                    class="resetButton"
                    size="mini"
                    @click="delAllSelectedSupplierstoreTableData()"
                  >批量删除</el-button>
                </div>
              </div>
            </el-row>

            <div class="w100">
                <div v-if="searchStoreFlag" class="f_r mb30">
                  <el-form
                    :inline="true"
                    :model="storeSearchForm"
                    size="mini"
                    ref="storeSearchForm"
                    :rules="storeSearchFormRules"
                  >
                    <el-form-item label="店铺编码：" prop="storecode" class="mr30">
                      <el-input v-model="storeSearchForm.storecode" clearable maxlength="80" placeholder="店铺编码" @input="changeRemark($event)"></el-input>
                    </el-form-item>
                    <el-form-item label="店铺名称：" prop="storename">
                      <el-input v-model="storeSearchForm.storename" clearable maxlength="80" placeholder="店铺名称" @input="changeRemark($event)"></el-input>
                    </el-form-item>
                    <el-form-item label prop="mpName">
                      <el-button
                        class="resetButton"
                        size="mini"
                        @click="resetStoreSearch()"
                      >重置</el-button>
                      <el-button class="resetButton" size="mini" @click="storeSearch()">查询</el-button>
                    </el-form-item>
                  </el-form>
                </div>
              </div>
            <el-table
              :data="storeTableData"
              v-loading="storeTableDataLoading"
              @selection-change="storeTableDataselectionChange"
            >
              <el-table-column type="selection"></el-table-column>
              <el-table-column label="店铺编号">
                <template slot-scope="scope">
                  <span>{{ scope.row.storecode}}</span>
                </template>
              </el-table-column>
              <el-table-column label="店铺名称">
                <template slot-scope="scope">
                  <span>{{ scope.row.storename}}</span>
                </template>
              </el-table-column>
              <el-table-column label="店铺类型">
                <template slot-scope="scope">
                  <span v-if="scope.row.storeType =='1'">线上店铺</span>
                  <span v-else>线下店铺</span>
                </template>
              </el-table-column>
              <el-table-column label="所属商家">
                <template slot-scope="scope">
                  <span>{{ scope.row.merchantName}}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" v-if="this.auth =='0'">
                <template slot-scope="scope">
                  <el-button type="text" class="textButton" @click="storeDelete(scope.row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="toolbar t_r">
              <el-pagination
                layout="total, sizes, prev, pager, next, jumper"
                @current-change="mainSroreMerchantRefreshPageRequest"
                :current-page="mainStoreMerchantForm.pageNo"
                :page-size="mainStoreMerchantForm.pageSize"
                :total="storeTableDataTatol"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="mainSroreMerchantHandleSizeChange"
              ></el-pagination>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div> -->

      <!--促销商品列表-->
      <div v-if="active == 3" class="tab-container createSet active3">
        <el-tabs v-model="productStatusTabs" @tab-click="productTabs">
          <el-tab-pane :label="'生效商品('+ (Number(merchantProductTotalCount) > 9999 ? '9999+' : merchantProductTotalCount) +')'" name="1">
              <div class="row-line-button t_r">
                <div style="width:100%">
                  <el-button
                    class="searchButton"
                    size="mini"
                    icon="el-icon-search"
                    @click="changeSearchMerchantProductFlag"
                  >搜索</el-button>
                  <!-- <el-button type="primary" size="mini" @click="addAllProduct">全部添加</el-button> -->
                  <el-button class="searchButton" size="mini" @click="add">添加促销商品</el-button>
                  <el-button class="resetButton" size="mini" @click="batchDelProduct">批量删除</el-button>
                  <el-button
                    icon="el-icon-document"
                    size="mini"
                    class="searchButton"
                    @click="downloadTemplate"
                    style="margin-right: 15px;"
                    v-if="false"
                  >模板下载</el-button>
                  <el-upload
                    class="avatar-uploader"
                    :show-file-list="false"
                    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                    v-if="false"
                  >
                    <el-button icon="el-icon-document-add" class="searchButton" size="mini" type="primary" v-if="false">商品导入</el-button>
                  </el-upload>

                </div>
              </div>

              <el-row>
                <div v-if="searchMerchantProductFlag">
                  <el-form
                    :inline="true"
                    :model="merchantProductSearchForm"
                    size="mini"
                    ref="merchantProductSearchForm"
                    class="rightForm"
                    :rules="merchantProductSearchFormRules"
                  >
                    <el-form-item label="商户：" prop="storeId" class="mb30">
                      <template>
                        <el-select v-model="merchantProductSearchForm.storeId" placeholder="全部" clearable>
                          <el-option
                            v-for="item in promotionStoreTableData"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          ></el-option>
                        </el-select>
                      </template>
                    </el-form-item>
                    <el-form-item label="商品编码：" prop="mpCode" class="mb30">
                      <el-input v-model="merchantProductSearchForm.mpCode" clearable maxlength="80" placeholder="商品编码"></el-input>
                    </el-form-item>
                    <el-form-item label="商品名称：" prop="mpName" class="mb30">
                      <el-input v-model="merchantProductSearchForm.mpName" clearable maxlength="80" placeholder="商品名称"></el-input>
                    </el-form-item>
                    <el-form-item label="商品类目：" prop="categoryName" class="mb30">
                      <el-input v-model="merchantProductSearchForm.categoryName" clearable maxlength="80" placeholder="商品类目"></el-input>
                    </el-form-item>
                    <el-form-item class="mb30">
                      <el-button class="resetButton" size="mini" plain @click="resetMerchantProductSearch()">重置</el-button>
                       <el-button class="resetButton" size="mini" @click="merchantProductSearch()">查询</el-button>
                    </el-form-item>
                  </el-form>
                </div>
              </el-row>
            <div class="tableTree">

              <el-table :data="merchantProductTableData"  row-key="id" default-expand-all :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                        @selection-change="repelSelectionChange"  class="tableStyle" v-loading="merchantProductTableDataLoading">
                <!-- <el-table-column type="selection" width="55"></el-table-column> -->
                <el-table-column align="left" width="30">
                  <template slot="header" slot-scope="scope">
                    <div class="isAllChecked" v-if="merchantProductTableData.length > 0">
                      <el-checkbox
                        :indeterminate="isIndeterminateProductCheck"
                        v-model="isAllProductChecked"
                        @change="handleCheckedAllProductChange"
                      ></el-checkbox>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="40">
                  <template slot-scope="scope">
                    <el-checkbox
                      :indeterminate="scope.row.isIndeterminateCheck"
                      v-model="scope.row.isCheck"
                      @change="handleCheckedProductChange(scope.row,$event)"
                    ></el-checkbox>
                  </template>
                </el-table-column>
                <el-table-column prop="mpCode" label="商品编码"  align="left"></el-table-column>
                <el-table-column prop="productName" label="商品名称" sortable align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.mpName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="storeName" label="商品分类" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.categoryName}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="stock" label="库存" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.stock}}</span>
                  </template>
                </el-table-column>
                <!-- <el-table-column prop="merchantName" label="商家名称" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.merchantName}}</span>
                  </template>
                </el-table-column> -->
                <el-table-column prop="storeName" label="所属商户" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.storeName}}</span>
                  </template>
                </el-table-column>
                 <el-table-column prop="storeCode" label="商户Code" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.storeCode}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="salePrice" label="原价（元）" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.salePrice}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="parentAllocationScale" label="平台分摊" v-if="filters.costAllocationFlag == '1'" align="center" width="160">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.parentAllocationScale"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="平台分摊"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="merchantAllocationScale" label="商户分摊" v-if="filters.costAllocationFlag == '1'" align="center" width="160">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.merchantAllocationScale"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="商户分摊"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="stockLimit" label="活动库存" align="center" width="160">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.stockLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="活动库存"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                    />
                  </template>
                </el-table-column>

                <el-table-column prop="individualLimit" label="个人限购" align="center" width="160">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.individualLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="个人限购"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="orderLimit" label="订单限购" align="center" width="160">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.orderLimit"
                      @blur="updatePriceOrLimit(scope.row)"
                      :size="size"
                      placeholder="订单限购"
                      :disabled="scope.row.disabled"
                      oninput="value=value.replace(/[^\d]/g,'')"
                      clearable
                      maxlength="10"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="200">
                  <template slot-scope="scope">
                    <el-button
                      @click.native.prevent="delMerchantProducts(scope.row.id)"
                      type="text"
                      size="small"
                    >删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!--分页栏-->
              <div class="toolbar t_r">
                <el-pagination
                  @size-change="handleSizeChangeMerchantProductTableData"
                  @current-change="handleCurrentChangeMerchantProductTableData"
                  :current-page="merchantProductSearchForm.start"
                  :page-sizes="[10]"
                  :page-size="merchantProductSearchForm.limit"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="merchantProductTableDataTotal"
                ></el-pagination>
              </div>
              </div>
          </el-tab-pane>
          <el-tab-pane :label="'互斥商品('+ (Number(mutexMerchantProductTotalCount) > 9999 ? '9999+' : mutexMerchantProductTotalCount) +')'" name="2">
              <div class="row-line-button t_r">
                <div style="width:100%">
                  <!-- <el-button type="primary" size="mini" @click="addAllProduct">全部添加</el-button> -->
                  <!-- <el-button type="primary" size="mini" @click="add">添加促销商品</el-button> -->
                  <!-- <el-button class="searchButton"  @click="batchRenewAdd">批量重新添加</el-button> -->
                </div>
              </div>
            <div class="tableTree">

              <el-table :data="mutexProductList"  row-key="id" default-expand-all :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                        @selection-change="batchRenewAddSelectionChange" class="tableStyle" v-loading="mutexProductListLoading">
                <!-- <el-table-column type="selection" width="55"></el-table-column> -->
                <el-table-column align="left" width="30">
                  <template slot="header" slot-scope="scope">
                    <div class="isAllChecked" v-if="mutexProductList.length > 0">
                      <el-checkbox
                        :indeterminate="isIndeterminateCheck"
                        v-model="isAllChecked"
                        @change="handleCheckedAllChange"
                        @click="scope.row"
                      ></el-checkbox>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column width="40">
                  <template slot-scope="scope">
                    <el-checkbox
                      :indeterminate="scope.row.isIndeterminateCheck"
                      v-model="scope.row.isCheck"
                      @change="handleCheckedChange(scope.row,$event)"
                    ></el-checkbox>
                  </template>
                </el-table-column>
                  <el-table-column prop="mpCode" label="商品编码" width="200"  align="left"></el-table-column>
                  <el-table-column prop="mpName" label="商品名称" width="200"></el-table-column>
                  <el-table-column prop="categoryName" label="商品分类" width="200"></el-table-column>
                  <el-table-column prop="stock" label="库存" width="200"></el-table-column>
                  <el-table-column prop="salePrice" label="原价（元）" width="200"></el-table-column>
                  <el-table-column prop="storeName" label="所属店铺" width="200"></el-table-column>
                  <el-table-column align="center" fixed="right" label="操作" width="390">
                    <template slot-scope="scope">
                      <el-button @click="getMutexInfo(scope.row)" v-if="scope.row.typeOfProduct==20" type="text" class="textButton" size="small">查看详情</el-button>
                      <el-button @click="renewAdd(scope.row)" v-if="scope.row.typeOfProduct==10 || scope.row.typeOfProduct==20" type="text" class="textButton" size="small">重新添加</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <div class="toolbar t_r" >
                  <el-pagination
                    @size-change="handleSizeChangeMutexProductList"
                    @current-change="handleCurrentChangeMutexProductList"
                    :current-page="mutexProductForm.start"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="mutexProductForm.limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="mutexProductTotal"
                  >
                  </el-pagination>
                </div>
              </div>
          </el-tab-pane>
        </el-tabs>

      </div>

      <div class="tab-container tab-success createSet" v-show="active==4">
        <div class="titleInfo">
          <img src="/static/images/success.png" />
          <span class="font20">活动创建成功!</span>
        </div>
        <div class="step-button2">
          <el-button class="resetButton" @click="detailList">查看活动列表</el-button>
          <template v-if="(4==filters.status && auditCount == 0) || [9,1].includes(filters.status)">
            <kt-button
              class="searchButton"

              :size="size"
              @click="shenheHuodong(0)"
              label="提交审核"
            ></kt-button>
          </template>
          <template v-if="[2].includes(filters.status)">
            <kt-button
               class="searchButton"

              :size="size"
              @click="shenheHuodong(1)"
              label="审核"
            ></kt-button>
          </template>
        </div>
      </div>
    </div>
    <div class="step-button">
      <el-button
        class="cancelButton"
        :plain="active != 1 && active != 4"
        :size="size"
        v-if="active != 1 && active != 4"
        @click="back"
      >上一步</el-button>
      <el-button class="searchButton" :size="size" @click="next" v-show="active!=4">下一步</el-button>
    </div>
    <!-- 选择参与商家 -->
    <el-dialog :title="'添加商家'" :visible.sync="editDialogVisible" :close-on-click-modal="false">
      <div>
        <div>
          <el-form :inline="true" :model="merchantForm" size="mini" ref="merchantForm" :rules="merchantFormRules">
            <el-form-item label="商家编号：" prop="orgNumber" class="w178">
              <el-input v-model="merchantForm.orgNumber" size="mini" clearable maxlength="80" placeholder="商家编号"></el-input>
            </el-form-item>
            <el-form-item label="商家名称：" prop="name" class="w178">
              <el-input v-model="merchantForm.name" size="mini" clearable maxlength="80" placeholder="商家名称"></el-input>
            </el-form-item>
            <el-form-item label="商家类型：" prop="merchantType" class="w178">
              <el-select v-model="merchantForm.merchantType" placeholder="全部" clearable>
<!--                <el-option label="全部" value=""></el-option>-->
                <el-option label="自营商家" value="1"></el-option>
                <el-option label="第三方商户" value="2"></el-option>
              </el-select>
            </el-form-item>

          </el-form>
          <el-row class="t_r mb30 mt20">
            <el-button class="resetButton" icon="el-icon-refresh" size="mini" @click="resetMerchantForm()">重置</el-button>
            <el-button
              class="searchButton"
              size="mini"
              @click="merchantFormFind()"
              icon="el-icon-search"
            >搜索</el-button>

          </el-row>
        </div>
        <div>
          <el-table
            :data="merchantTableData"
            v-loading="merchantTableDataLoading"
            @selection-change="addSelectionChange"
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column align="center" label="商家编号">
              <template slot-scope="scope">
                <span>{{ scope.row.orgNumber}}</span>
              </template>
            </el-table-column>
            <el-table-column width="300px" align="center" label="商家名称">
              <template slot-scope="scope">
                <span>{{ scope.row.name}}</span>
              </template>
            </el-table-column>
            <el-table-column width="300px" align="center" label="商家类型">
              <template slot-scope="scope">
                <span v-if="scope.row.merchantType =='1'">自营商家</span>
                  <span v-if="scope.row.merchantType =='2'">第三方商户</span>
              </template>
            </el-table-column>

          </el-table>
          <!--分页栏-->
          <div class="toolbar t_r" v-if="merchantTableData.length > 0">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              @current-change="refreshPageRequest"
              :current-page="merchantForm.start"
              :page-size="merchantForm.limit"
              :total="merchantTableDataTatol"
              :page-sizes="[10, 20, 30, 40]"
              @size-change="handleSizeChange"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button class="cancelButton" :size="size" @click.native="editDialogVisible = false">取消</el-button>
        <el-button
          :size="size"
          class="searchButton"
          @click.native="editDialogVisible = false"
          @click="merchantTableDataSubmit"
        >确定</el-button>
      </div>
    </el-dialog>
    <!-- 选择参与店铺 -->
    <el-dialog :title="'添加参与店铺'" :visible.sync="editDialogVisible2" :close-on-click-modal="false">
      <div>
        <div>
          <el-form :inline="true" :model="storeForm" size="mini" ref="storeForm" :rules="storeFormRules">
            <el-form-item label="店铺名称：" prop="storename" class="w178 mb30">
              <el-input v-model="storeForm.storename" size="mini" clearable maxlength="80" placeholder="店铺名称"></el-input>
            </el-form-item>
            <el-form-item label="店铺编号：" prop="storecode" class="w178">
              <el-input v-model="storeForm.storecode" size="mini" clearable maxlength="80" placeholder="店铺编号"></el-input>
            </el-form-item>
            <el-form-item label="所属商家名称：" prop="merchantName" class="w178">
              <el-input v-model="storeForm.merchantName" size="mini" clearable maxlength="80" placeholder="所属商家名称"></el-input>
            </el-form-item>
            <el-form-item label="店铺类型：" prop="storeType" class="w178" >
              <el-select v-model="storeForm.storeType" placeholder="全部" size="mini" clearable>
<!--                <el-option label="全部" value=""></el-option>-->
                <el-option label="自营店铺" value="0"></el-option>
                <el-option label="入驻店铺" value="1"></el-option>
              </el-select>
            </el-form-item>

          </el-form>
          <el-row class="mb30 t_r mt20">
            <el-button class="resetButton" icon="el-icon-refresh" size="mini" @click="resetStoreForm()">重置</el-button>
            <el-button class="searchButton" size="mini" @click="storeFormFind()" icon="el-icon-search">搜索</el-button>

          </el-row>
        </div>
        <div>
          <el-table
            :data="storeTableData2"
            v-loading="storeTableData2Loading"
            @selection-change="storeTableData2AddSelectionChange"
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column prop="id" label="店铺编号" width="320px">
              <template slot-scope="scope">
                <span>{{ scope.row.storeCode}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="店铺名称">
              <template slot-scope="scope">
                <span>{{ scope.row.storeName}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="storeType" label="店铺类型">
              <template slot-scope="scope">
                <span v-if="scope.row.storeType == '0'">自营店铺</span>
                <span v-if="scope.row.storeType == '1'">入驻店铺</span>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="所属商家">
              <template slot-scope="scope">
                <span>{{ scope.row.merchantName}}</span>
              </template>
            </el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar t_r" v-if="storeTableData2.length > 0">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              @current-change="refreshPageRequestStore"
              :current-page="merchantFormStore.start"
              :page-size="merchantFormStore.limit"
              :total="merchantTableDataTatolStore"
              :page-sizes="[10, 20, 30, 40]"
              @size-change="handleSizeChangeStore"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button class="cancelButton" :size="size" @click.native="editDialogVisible2 = false">取消</el-button>
        <el-button
          :size="size"
          class="searchButton"
          @click.native="editDialogVisible2 = false"
          @click="storeTableData2Click"
        >确定</el-button>
      </div>
    </el-dialog>
    <!-- 导入、上传弹窗-->
    <el-dialog
      :title="operation?'商品导入':'下载模板'"
      :inline="true"
      class="el-dialog-style"
      :visible.sync="uploadVisible"
      :close-on-click-modal="false"
    >
      <div>
        <el-button  class="searchButton" icon="el-icon-download" v-show="operation">商品导入模板</el-button>
        <el-button  class="searchButton" icon="el-icon-upload" v-show="operation==false">商品导入</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="'互斥提示'"
      :visible.sync="mutexDetailDialogVisible"
      :close-on-click-modal="false"
    >
      <div>
        <div>
          <el-row>
            <el-col class="mb20 t_l">以下商品正在参与同类型的促销活动，本次新增将无法生效！</el-col>
            <!--            <el-col :span="8"><div class="grid-content bg-purple-light"></div></el-col>-->
            <!--            <el-col :span="8"><div class="grid-content bg-purple"></div></el-col>-->
          </el-row>
          <!--          {"promotionId":26, "promName":"测试互斥活动1","mutexTime":"2019-09-26 14:28:31 - 2019-10-04 14:28:34","mutexChannel":"BBC","mutexStroeName":"张小二bbc店铺"},-->
          <el-table :data="mutexPromotionTable"  v-loading="mutexPromotionTableLoading">
            <el-table-column align="center" label="互斥活动ID">
              <template slot-scope="scope">
                <span>{{ scope.row.promotionId}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥活动名称">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  class="textButton"
                  @click="seeMoreDeatil(scope.row)"
                >{{ scope.row.promName}}</el-button>
                <!--                <span>{{ scope.row.promName}}</span>-->
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥活动时间">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexTime}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥渠道">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexChannel}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="互斥商户">
              <template slot-scope="scope">
                <span>{{ scope.row.mutexStroeName}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button  class="searchButton" :size="size" @click.native="mutexDetailDialogVisible = false">关闭</el-button>
      </div>
    </el-dialog>


    <!-- 互斥活动详情 -->
    <el-dialog :visible.sync="mutexPromotionVisible" title="互斥活动详情" width="70%" :close-on-click-modal="false">
      <div>
        <el-table :data="mutexPromotionList" ref="multipleTable" :row-class-name="tableRowClassName"  :size="size" v-loading="mutexPromotionListLoading">
          <el-table-column prop="promotionCode" width="280" label="互斥活动编码" sortable align="center"></el-table-column>
          <el-table-column prop="promName"  width="280" label="互斥活动名称" align="center">
            <template slot-scope="scope">
              <el-button @click="linkInfoByMutexProduct(scope.row.promotionId,scope.row.promType)" type="text" class="textButton" size="small">{{scope.row.promName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="goodsCategory"  width="360" label="互斥活动时间" align="center">
            <template slot-scope="scope">
                <span>{{scope.row.startTime}} - {{scope.row.endTime}}</span>
              </template>
          </el-table-column>
          <el-table-column prop="storeName" label="活动状态" align="center" width="150">
            <template slot-scope="scope">
              <span class="color333 font18" v-if="scope.row.status == 0">待提交</span>
              <span class="color333 font18" v-else-if="scope.row.status == 1">待提交</span>
              <span class="color333 font18" v-else-if="scope.row.status == 2">待审核</span>
              <span class="color333 font18" v-else-if="scope.row.status == 3">未开始</span>
              <span class="color333 font18" v-else-if="scope.row.status == 4">审核不通过</span>
              <span class="color333 font18" v-else-if="scope.row.status == 5">进行中</span>
              <span class="color333 font18" v-else-if="scope.row.status == 6">已过期</span>
              <span class="color333 font18" v-else-if="scope.row.status == 7">已关闭</span>
              <span class="color333 font18" v-else-if="scope.row.status == 8">已结束</span>
              <span class="color333 font18" v-else-if="scope.row.status == 9">活动草稿</span>
            </template>
          </el-table-column>
          <el-table-column prop="creatorName" label="创建人" align="center" width="200"></el-table-column>
          <el-table-column prop="deptName"  label="创建组织" align="center" width="200"></el-table-column>
        </el-table>
        <!--分页栏-->
        <div class="toolbar t_r">
          <el-pagination
            @size-change="mutexPromotionListSizeChange"
            @current-change="mutexPromotionListCurrentChange"
            :current-page="mutexPromotionForm.start"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="mutexPromotionForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="mutexPromotionListTotal"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer t_c">
        <el-button  class="searchButton" :size="size" @click.native="mutexPromotionVisible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import marketRequest from "@/market/request/marketRequest";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { darkmagenta } from "color-name";
import { quillEditor } from "vue-quill-editor";
import TreeSelect from "@/views/Core/TreeSelect";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import { getAllRow, changeChild, changeParent } from "@/assets/js/tableTree.js";
import {
  singleFrontPromTypesRadio,
  chanelCodesRadio,
  proPlatformRadio,
  proUserTypeRadio,
  proMemberTypeRadio,
  proMemberLevelRadio
} from "@/market/dict/marketDict";
const channelArr = ["bbc"];
const channelArr1 = ["APP端", "PC端", "微信"];
const channelArr2 = ["新用户", "老用户"];
const channelArr3 = ["普通会员"];
const channelArr4 = ["注册用户", "VIP会员", "金卡"];
export default {
  name: "Tab",
  components: {
    KtButton,
    TableColumnFilterDialog,
    quillEditor,
    TreeSelect
  },
  created: function() {
    if (typeof this.$route.query.active != "undefined") {
      this.active = this.$route.query.active;
    }
    if (typeof this.$route.query.id != "undefined") {
      this.promotionId = this.$route.query.id;
      this.promotion.id = this.$route.query.id;

      this.getPromotionDetail(this.promotionId);
    }
  },
  data() {
    var checkOverlayAppNum = (rule, value, callback) => {
      var regEn = /^\+?[1-9][0-9]*$/;
      if (!regEn.test(value)) {
        callback(new Error("请输入正整数"));
      }
      callback();
    };
    /**
     * 会员类型
     */
    var checkMemType = (rule, value, callback) => {
      if(this.selectMemTypes == null || this.selectMemTypes.length < 1){
        return callback(new Error("请选择会员类型"));
      }

      return callback();

    };
    var isNumber = (rule, value, callback) => {
      if (value === "") {
        return callback();
      } //这是用来判断如果不是必须输入的，则直接跳出
      const r = /^\+?[1-9][0-9]*$/; // 正整数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error("必须为正整数"));
      } else {
        return callback();
      }
    };
    var checkConditonValue = (rule, value, callback) => {
      var r = /^\+?[1-9][0-9]*$/; // 2位小数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error("请输入正整数"));
      } else {
        return callback();
      }
    };
    var checkContentValue = (rule, value, callback) => {
      var reg = /^(?!0(\.0{1,1})?$)(\d(\.\d{1,1})?|10)$/;
      var r = /^\d+\.?\d{0,2}$/; // 2位小数
      if (
        (this.filters.frontPromType == 12 ||
          this.filters.frontPromType == 14) &&
        !reg.test(value)
      ) {
        return callback(new Error("请输入0到10直接的数字(支持1位小数)"));
      }
      if (this.filters.frontPromType == 13 && !r.test(value)) {
        return callback(new Error("请输入数字(支持2位小数)"));
      }
      return callback();
    };
    /**
     * 新老用户
     */
    var checkUserType = (rule, value, callback) => {
      if(this.selectUserType == null || this.selectUserType.length < 1){
        return callback(new Error("请选择新老用户"));
      }
      return callback();
    };
    var checkWaringNum = (rule, value, callback) => {
        if(value && Number(value) > 100){
          return callback(new Error("必须小于等于100%"));
        }else{
          return callback();
        }
    };
    return {
      channelOption:[],
      merchantFormRules: {
        // orgNumber: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // name: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      storeFormRules: {
        // storename: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // storecode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // merchantName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      merchantSearchFormRules: {
        // orgNumber: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // merchantName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      storeSearchFormRules: {
        // storecode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // storename: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      productFormRules: {
        // goodsName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // thirdSpuId: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // goodsCategory: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // storeName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      merchantProductSearchFormRules: {
        // mpCode: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // mpName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
        // categoryName: { min: 0, max: 80, message: "字数0-80个字符", trigger: "blur" },
      },

      auditCount: 0,
      merchantProductTotalCount: 0,
      deptType: localStorage.getItem("deptType"), //当前登录用户所属组织类型
      // 活动时间校验
      timeCheck: {
        disabledDate: time => {
          if (this.promotionStartEndTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() > new Date(this.promotionStartEndTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        }
      },
      productTableData2Selection: [], //批量删除时候临时存储
      storeSearchForm: {
        promotionId: this.promotionId,
        merchantType: "2",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      searchMerchantFlag: false,
      searchStoreFlag: false,
      merchantSearchForm: {
        merchantName: null,
        orgNumber: null,
        promotionId: this.promotionId,
        merchantType: "1",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      templateDialogVisible: false,
      filtersRules: {
        contentValue: [
          { required: true, validator: checkContentValue, trigger: "blur" }
        ],
        conditionValue: [
          { required: true, validator: checkConditonValue, trigger: "blur" }
        ],
        freightValue: [{ validator: checkOverlayAppNum, trigger: "change" }],
        freightReducedValue: [
          { validator: checkOverlayAppNum, trigger: "change" }
        ],
        overlayAppNum: [{ validator: checkOverlayAppNum, trigger: "change" }],
        parentAllocationScale: [
          { required: true, validator: isNumber, trigger: "change" }
        ],
        childAllocationScale: [
          { required: true, validator: isNumber, trigger: "change" }
        ],
        merchantAllocationScale: [
          { required: true, validator: isNumber, trigger: "change" }
        ],
        storeAllocationScale: [
          { required: true, validator: isNumber, trigger: "change" }
        ],
        templateDialogVisible: false,
        promName: [
          { required: true, message: "请输入活动名称" },
          {
            min: 3,
            max: 60,
            message: "长度在 3 到 60 个字符",
            trigger: "change"
          }
        ],
        promotionStartEndTime: [
          { required: true, message: "请选择时间", trigger: "blur" }
        ],
        frontPromType: [
          { required: true, message: "请选择促销类型", trigger: "blur" }
        ],
        mainGiftSameFlag: [
          { required: true, message: "请选择赠品类型", trigger: "blur" }
        ],
        overlayAppFlag: [
          { required: true, message: "请选择是否叠加应用", trigger: "blur" }
        ],
        promotionRules: [
          { required: true, message: "请设置优惠设置", trigger: "blur" }
        ],
        parcelsFlag: [
          { required: true, message: "请选择是否包邮", trigger: "blur" }
        ],
        costAllocationFlag: [
          { required: true, message: "请选择是否分摊", trigger: "blur" }
        ],
        channelCodes: [
          { required: true, message: "请选择使用渠道", trigger: "blur" }
        ],
        budget: [
          { required: true, message: "请输入活动预算", trigger: "blur" }
        ],
        warningNum:[
          { required: false, validator: checkWaringNum, trigger: ["change","blur"] }
        ],
        selectUserType: [{ required: true, validator: checkUserType, trigger: "change" }],
        selectMemTypes: [{required: true, validator: checkMemType , trigger: "change"}],
      },
      mutexDetailDialogVisible: false,
      mutexPromotionTable: [],
      formLabelWidth: "120px",
      // setep3--start
      productPromotionListObject: { productPromotionList: [] },
      productAddSelection: [],
      tableDataTwo: [],
      searchMerchantProductFlag: false,
      merchantProductTableData: [],
      merchantProductTableDataTotal: 0,
      dialogVisibleTwo: false,
      tabsIndex: "first",
      labelPosition: "right",
      productForm: {
        start: 1,
        limit: 10,
        goodsName: null,
        thirdSpuId: null,
        categoryName: null,
        storeName: null,
        productName: "",
        productNo: "",
        barCode: "",
        chineseName: "",
        code: ""
      },
      // setep3--end
      adminDataForm: {
        auditRemark: null
      },
      adminDataFormRules: {
        auditRemark: [
          { required: true, message: "审核意见不能为空", trigger: "blur" }
        ]
      },
      dialogVisibleAdmin: false,
      shenhe: 0,
      size: "small",
      editDialogVisible: false,
      editDialogVisible2: false,
      url: "./static/shop.png",
      url2: "./static/shop2.png",
      content: null,
      editorOption: {},
      size: "small",
      productVisible: false,
      uploadVisible: false,
      operation: false, // true:商品导入, false:下载模板
      activeName: 0,
      setUp: false,
      search: false,
      tagList: [],
      filters: {
        warningNum:null,
        budget:null,
        searchKeyword:null,
        id: null,
        promType: 7,
        labelId: null,
        promName: null,
        frontPromType: 12,
        foldingFlag: 1,
        overLimitRule: 2,
        channelCodes: null,
        proPlatform: [1],
        proUserType: null,
        proMemberType: [1],
        proMemberLevel: [2],
        createMerchantId: 11,
        contentType: 1,
        status: 9,
        // "creator":1,
        // "creatorName":"wys",
        // "updator":1,
        // "updatorName":"wys",
        rejectCouponsFlag: 0,
        ruleId: null,
        parcelsFlag: 0,
        overlayAppNumFlag: 0,
        overlayAppNum: null,
        description: "",
        conditionValue: null,
        contentValue: null,
        promotionRules: [
          { conditionValue: null, contentValue: null, id: null, level: 1 }
        ],
        mainGiftSameFlag: 1,
        costAllocationFlag: 1,
        parentAllocationScale: null,
        childAllocationScale: null,
        merchantAllocationScale: null,
        storeAllocationScale: null,
        templateFlag: 1,
        storeArea: -1,
        userArea: -1,
        promotionStartEndTime: [],
        freightType: 1,
        freightValue: null,
        freightReducedValue: null,
        overlayAppFlag: 0
      },
      editLoading: false,
      merchantProductSearchForm: {
        promotionId: null,
        merchantId: null,
        storeId: null,
        mpCode: null,
        mpName: null,
        categoryName: null,
        start: 1,
        limit: 10
      },
      dataForm: {},
      modalShow: 1,
      multipleSelection: [],
      batchDeleteSelection: [],
      repelSelection: [],
      addSelection: [],
      businessList: [{ id: "001", name: "张小二服饰", type: "自营商家" }],
      shopList: [{ id: "161616", name: "张小二bbc店铺", type: "直营" }],
      tableData: [
        {
          id: 1912250010887324,
          productName: "新供应商001",
          unit: "件",
          shopName: "张小二服饰",
          price: 1.2,
          markdown: 1,
          shopLimit1: 100,
          shopLimit2: 100,
          shopLimit3: 100
        },
        {
          id: 1912250010887323,
          productName: "新供应商002",
          unit: "件",
          shopName: "张小二服饰",
          price: 1.3,
          markdown: 1,
          shopLimit1: 100,
          shopLimit2: 100,
          shopLimit3: 100
        }
      ],
      active: 1,
      radio1: 3,
      radio2: 3,
      radio3: 3,
      radio4: 3,
      radio5: 3,
      shopList: [],
      businessList: [],
      checkAll: false,
      checkAll1: false,
      checkAll2: true,
      checkAll3: false,
      checkAll4: false,
      checkedCities: [110001],
      checkedCities1: ["APP端", "PC端", "微信"],
      checkedCities2: ["新用户", "老用户"],
      checkedCities3: ["普通会员"],
      checkedCities4: ["注册用户", "VIP会员", "金卡"],
      frontPromTypesRadios: singleFrontPromTypesRadio,
      chanelCodesRadios: chanelCodesRadio,
      proPlatformRadios: proPlatformRadio,
      proUserTypeRadios: proUserTypeRadio,
      proMemberTypeRadios: proMemberTypeRadio,
      proMemberLevelRadios: proMemberLevelRadio,
      cities: channelArr,
      cities1: channelArr1,
      cities2: channelArr2,
      cities3: channelArr3,
      cities4: channelArr4,
      isIndeterminate: true,
      isIndeterminate1: true,
      isIndeterminate2: true,
      isIndeterminate3: true,
      isIndeterminate4: true,
      options: [
        {
          value: "1",
          label: "京东直营"
        },
        {
          value: "2",
          label: "淘宝旗舰"
        },
        {
          value: "3",
          label: "良品铺子1店"
        }
      ],
      value5: [],
      options2: [
        {
          value: "1",
          label: "良品铺子"
        }
      ],
      value6: [],
      isClearable: true, // 可清空（可选）
      isAccordion: true, // 可收起（可选）
      valueId: 20, // 初始ID（可选）
      props: {
        // 配置项（必选）
        value: "id",
        label: "name",
        children: "children"
        // disabled:true
      },
      // 选项列表（必选）
      list: [
        { id: 2, parentId: 0, name: "居家生活", rank: 1 },
        { id: 4, parentId: 0, name: "数码家电", rank: 1 },
        { id: 5, parentId: 0, name: "母婴保健", rank: 1 },
        { id: 6, parentId: 0, name: "美食酒水", rank: 2 },
        { id: 7, parentId: 0, name: "个护清洁", rank: 2 },
        { id: 9, parentId: 0, name: "好物甄选", rank: 2 },

        { id: 101, parentId: 2, name: "个护健康", rank: 3 },
        { id: 102, parentId: 2, name: "3C数码", rank: 4 },
        { id: 103, parentId: 2, name: "汽车用品", rank: 5 },
        { id: 202, parentId: 101, name: "按摩电器", rank: 5 },
        { id: 203, parentId: 101, name: "个护美容", rank: 5 }
      ],

      //第一步添加成功赋值
      //外部赋值-----------------start
      promotionId: null,
      auth: 0,
      //外部赋值-----------------start

      promotion: {
        //促销id
        id: "",
        promotionId: "1",
        merchantType: "1"
      },
      pomotionListObject: { pomotionList: [] },
      // pomotionList:[
      //   {
      //   // id:"0",
      //   promotionId:"0",
      //   merchantId:"0",
      //   merchantType:0,
      //   merchantName:"",
      //   storeId:"0",
      //   // createTime:"2020-01-15 11:38:41",
      //   // creator:"0",
      //   // creatorName:"",
      //   // updateTime:"2020-01-15 11:38:41",
      //   // updator:"0",
      //   // updatorName:""
      // }
      // ],
      mainMerchantForm: {
        promotionId: this.promotionId,
        merchantType: "1",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      mainMerchantTableDataTatol: 0,
      //---------------------------商家------------------------------------------------start
      merchantForm: {
        start: 1,
        limit: 10,
        name: null,
        orgNumber: null,
        merchantType: null
      },
      merchantFormStore: {
        start: 1,
        limit: 10
      },
      merchantTableDataTatol: 0,
      merchantTableDataTatolStore: 0,
      merchantTableData: [],
      //选择的商家列表
      merchantTableData2: [],
      promotionStoreTableData: [],
      //---------------------------商家------------------------------------------------end
      storeForm: {
        start: 1,
        limit: 10,
        merchantIds: "",
        storename: "",
        storecode: "",
        orgNumber: "",
        merchantName: "",
        storeType: ""
      },

      mainStoreMerchantForm: {
        promotionId: this.promotionId,
        merchantType: "2",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      storeTableDataTatol: 0,
      storeTableData: [],
      //选择店铺
      storeTableData2Tatol: 0,
      storeTableData2: [],
      //选择店铺
      addSelectionStoreTableData2: [],
      merchantTableData2Selection: [],
      merchantTableData2SelectionIndex: 0,
      storeTableDataSelection: [],
      storeTableDataSelectionIndex: 0,

      // -----------------------------------商品开始属性-----------------------------------start

      productTableDataTotal: 0,
      productTableData: [],
      productEditLoading: false,
      productPromotion: {
        //促销id
        promotionId: "1"
      },

      mainProductForm: {
        promotionId: this.promotionId,
        start: 1,
        limit: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },

      merchantProductTableDataTotal: 0,

      merchantProductTableDataMutex: [
        {
          id: 1912250010887324,
          promotionId: 2001100000003832,
          mpCode: 2001100000003832,
          productName: "新供应商001",
          unit: "件",
          merchantName: "张小二服饰",
          price: 1.2,
          contentType: 1,
          channelMerchantLimit: 100,
          channelStoreLimit: 100,
          channelIndividualLimit: 100,
          orderLimit: 100
        },
        {
          id: 1912250010887323,
          promotionId: 2001100000003832,
          mpCode: 200110000000384,
          productName: "新供应商002",
          unit: "件",
          merchantName: "张小二服饰",
          price: 1.2,
          contentType: 1,
          channelMerchantLimit: 10,
          channelStoreLimit: 10,
          channelIndividualLimit: 10,
          orderLimit: 1
        }
      ],

      merchantProductTableDataMutexTotal: 0,
      channelList: [], //渠道Tree List
      channlProps: {
        children: "children",
        label: "childName"
      },

      // -----------------------------------商品结束属性-----------------------------------end

      productStatusTabs: "1", //商品tabs

      mutexMerchantProductTotalCount: 0, //互斥Sku总条数
      mutexProductList: [], //互斥商品List
      mutexProductForm: {
        start: 1,
        limit: 10,
        promotionId: this.promotionId,
        mutexFlag: 1 //互斥标识
      },
      mutexProductTotal: 0, //互斥分页总条数
      showButtons: true, //功能按钮
      mutexPromotionList: [], //查看详情弹窗
      mutexPromotionListTotal: 0,
      mutexPromotionVisible: false,
      mutexPromotionForm: {
        promType: 1,
        start: 1,
        limit: 10
      },
      isAllChecked: false,//全选
      isIndeterminateCheck: false,//全选 checkbox 的不确定状态
      allData: [],//全选 操作数据

      isAllProductChecked: false,//全选
      isIndeterminateProductCheck: false,//全选 checkbox 的不确定状态
      allProductData: [],//全选 操作数据

      //会员等级 会员类型
      memberGradeList: [],
      reloadMemLevel: true,

        //会员类型
        memTypeCheckAll: true,
        memChannelCheckAll: true,
        selectMemTypes: [1, 2, 3],
        selectMemChannels: [1, 2, 3],
        selectMemTypes: [1, 2, 3],
        channelId: [1, 2, 3],
        channelIdCheckAll: true,
        channelIdIsIndeterminate: false,
        memTypeIsIndeterminate: false,
        memChannelIsIndeterminate: false,
        tableDataTwoLoading: false,
        merchantTableData2Loading: false,
        storeTableDataLoading: false,
        merchantProductTableDataLoading: false,
        mutexProductListLoading: false,
        merchantTableDataLoading: false,
        storeTableData2Loading: false,
        mutexPromotionTableLoading: false,
        mutexPromotionListLoading: false,
        userTypeCheckAll: true,
        selectUserType: [1, 2],
        userTypeIsIndeterminate: false,
      };
    },
    methods: {
      //新老用户
      handleCheckAllUserTypeChange(val) {
        this.selectUserType = val ? [1, 2] : [];
        this.userTypeIsIndeterminate = false;
      },
      handleCheckedUserTypeChange(value) {
        let checkedCount = value.length;
        this.userTypeCheckAll = checkedCount === 2;
        this.userTypeIsIndeterminate = checkedCount > 0 && checkedCount < 2;
      },
      getUuid() {
        var s = [];
        var hexDigits = "0123456789abcdef";
        for (var i = 0; i < 36; i++) {
          s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
        s[8] = s[13] = s[18] = s[23] = "-";

      var uuid = s.join("");
      return uuid;
    },

      //会员类型
      handleCheckAllMemTypeChange(val) {
        this.selectMemTypes = val ? [1, 2, 3] : [];
        this.memTypeIsIndeterminate = false;
      },
      handleCheckedMemTypeChange(value) {
        let checkedCount = value.length;
        this.memTypeCheckAll = checkedCount === 3;
        this.memTypeIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },


      //会员类型
      handleCheckAllMemChannelChange(val) {
        this.selectMemChannels = val ? [1, 2, 3] : [];
        this.memChannelIsIndeterminate = false;
      },
      handleCheckedMemChannelChange(value) {
        let checkedCount = value.length;
        this.memChannelCheckAll = checkedCount === 3;
        this.memChannelIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },

    //渠道
      handleCheckAllChannelIdChange(val) {
        this.channelId = val ? [1,2,3] : [];
        this.channelIdIsIndeterminate = false;
      },
      handleCheckedChannelIdChange(value) {
        let checkedCount = value.length;
        this.channelIdCheckAll = checkedCount === 3;
        this.channelIdIsIndeterminate = checkedCount > 0 && checkedCount < 3;
      },

    changeSearchMerchantProductFlag(){
      this.searchMerchantProductFlag = !this.searchMerchantProductFlag;
      this.resetForm("merchantProductSearchForm");
    },
    getPromotionStoreTableData(){
      let this_ = this;
      let param = {"promotionId":this.promotionId,"merchantType":2,"pageNo":1, "pageSize":100000};
      this.utils.request.promotionMerchantList(param, res => {
        if (res.code == "0000") {
          this_.promotionStoreTableData = res.data.list.map((ele, index) => {
            let promotionStore = {};
            promotionStore.id = ele.storeId;
            promotionStore.name = ele.storename;
            return promotionStore;
          });
        }
      });
    },
    /**
     * 查询互斥商品
     */
    getMutexProductList() {
      this.mutexProductListLoading = true;
      var this_ = this;
      this.mutexProductForm.promotionId = this.promotionId;
      marketRequest.getProductListV3(this.mutexProductForm, res => {
        if (res.code == "0000") {
          this_.mutexProductList = res.data.rows;
          this_.mutexProductTotal = res.data.total;
          this_.mutexMerchantProductTotalCount = res.data.totalCount;
          //操作数据
          this_.allData = getAllRow(this_.mutexProductList, []);
          this_.isAllChecked = false;
          this_.isIndeterminateCheck = false;
        }
        this_.$nextTick(() =>{
          this_.mutexProductListLoading = false;
        })
      });
    },
    /**
     * 每页条数改变触发
     */
    handleSizeChangeMutexProductList(val) {
      this.mutexProductForm.limit = val;
      this.mutexProductForm.start = 1;
      this.getMutexProductList();
    },
    /**
     * 换页刷新
     */
    handleCurrentChangeMutexProductList(val) {
      this.merchantProductSearchForm.start = val;
      this.getMutexProductList();
    },

    /**
     * 互斥商品重新添加
     */
    renewAdd(row) {
      let that = this;
      let param = {};
      var productIdList = [];
      param.promotionId = row.promotionId;
      param.promotionType = 1;
      // productIdList.push(row.id);
      if (row.typeOfProduct == "10") {
        row.children.forEach(item => {
          productIdList.push(item.id);
        });
      } else if (row.typeOfProduct == "20") {
        productIdList.push(row.id);
      }
      param.productIdList = productIdList;
      this.utils.request.renewAddMutexProduct(param, res => {
        if (res.code == "0000") {
          that.getMutexProductList();
          that.getProductListV2(0, null);

          let data = res.data;
          if (data.businessCode == "0001") {
            this.$message({ message: data.businessMsg, type: "success" });
          } else if (data.businessCode == "0002") {
            this.$message({ message: data.businessMsg, type: "error" });
          } else if (data.businessCode == "0003") {
            this.$alert(data.businessMsg, "提示", {
              confirmButtonText: "知道了",
              callback: action => {}
            });
          }
        }
      });
    },

    /**
     * 批量重新添加选择数据
     */
    batchRenewAddSelectionChange(val) {
      this.batchRenewAddSelection = val;
    },

    /**
     * 批量重新添加
     */
    batchRenewAdd() {
      //
      let that = this;
      let param = {};
      var productIdList = [];
      param.promotionId = this.promotionId;
      param.promotionType = 1;
      this.allData.forEach(function(item,index,array){
        if(item.typeOfProduct == '20' && item.isCheck){
          productIdList.push(item.id);
        }
      });
      param.productIdList = productIdList;
      this.utils.request.renewAddMutexProduct(param,res=>{
        if(res.code=='0000'){
          that.getMutexProductList();
          that.getProductListV2(0, null);

          let data = res.data;
          if(data.businessCode == '0001'){
            this.$message({message: data.businessMsg, type: "success"});
          }else if(data.businessCode == '0002'){
            this.$message({message:data.businessMsg, type: "error"})
          }else if(data.businessCode == '0003'){
            this.$alert(data.businessMsg, '提示', {
              confirmButtonText: '知道了',
              callback: action => {}
            });
          }
        }
      });
    },
    /**
     * 生效商品 互斥商品tab选中触发
     */
    productTabs(tab) {
      if (tab.index == 0) {
        this.showButtons = true;
      } else {
        this.showButtons = false;
      }
    },
    /**
     * 互斥商品查看详情
     */
    getMutexInfo(row) {
      let that = this;
      this.mutexPromotionForm.start = 1;
      this.mutexPromotionForm.limit = 10;
      this.mutexPromotionForm.promotionId = this.promotionId;
      this.mutexPromotionForm.promotionMerchantProductId = row.id;
      this.getPromotionMutexListByProductId();
    },
    getPromotionMutexListByProductId() {
      this.mutexPromotionListLoading = true;
      let that = this;
      this.utils.request.getPromotionMutexListByProductId(
        this.mutexPromotionForm,
        res => {
          if (res.code == "0000") {
            that.mutexPromotionList = res.data.rows;
            that.mutexPromotionListTotal = res.data.total;
            that.mutexPromotionVisible = true;
          }
          that.$nextTick(() =>{
            that.mutexPromotionListLoading = false;
          })
        }
      );
    },

    /**
     * 每页条数改变触发
     */
    mutexPromotionListSizeChange(val) {
      this.mutexPromotionForm.limit = val;
      this.mutexPromotionForm.start = 1;
      this.getPromotionMutexListByProductId();
    },
    /**
     * 换页刷新
     */
    mutexPromotionListCurrentChange(val) {
      this.mutexPromotionForm.start = val;
      this.getPromotionMutexListByProductId();
    },

    resetPromotionRule(start) {
      for (let i = this.filters.promotionRules.length - 1; i >= 0; i--) {
        if (start == 1 && i == 0) {
        } else {
          this.removePromotionRuleSet(i, this.filters.promotionRules[i]);
        }
      }
      if (this.filters.promotionRules.length == 0) {
        this.filters.promotionRules.push({
          conditionValue: null,
          contentValue: null,
          id: null,
          level: 1
        });
      }
      this.$refs.filters.clearValidate("promotionRules.0.conditionValue");
      this.$refs.filters.clearValidate("promotionRules.0.contentValue");
    },
    checkProductLimits(row) {
        let regPos = /^[1-9]([0-9]*)$/; // 非负整数
        if(row.stockLimit && !regPos.test(row.stockLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if(row.parentAllocationScale || row.merchantAllocationScale) {
          if (row.parentAllocationScale && !regPos.test(row.parentAllocationScale)) {
            this.$message({message: "只能输入正整数", type: "error"});
            return false;
          }
          if (row.merchantAllocationScale && !regPos.test(row.merchantAllocationScale)) {
            this.$message({message: "只能输入正整数", type: "error"});
            return false;
          }
          if (Number(row.parentAllocationScale) + Number(row.merchantAllocationScale) != 100) {
            this.$message({message: "平台和商家分摊比例总和不为100", type: "error"});
            return false;
          }
        }
        if(row.individualLimit && !regPos.test(row.individualLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if(row.orderLimit && !regPos.test(row.orderLimit)){
          this.$message({ message: "只能输入正整数", type: "error" });
          return false;
        }
        if(Number(row.stockLimit) > row.stock){
          this.$message({ message: "活动库存需小于等于商品库存", type: "error" });
          return false;
        }
        if(Number(row.orderLimit) > Number(row.individualLimit)){
          this.$message({ message: "订单限购需小于等于个人限购", type: "error" });
          return false;
        }
      return true;
    },
    getPromotionDetail(promotionId) {
      //获取促销基本信息详情
      let params = { id: promotionId },
        _this = this;
      this.utils.request.promotionDetailById(params, res => {
        if (res.code == "0000") {
          _this.filters.id = res.data.id;
          _this.filters.promType = res.data.promType;
          _this.filters.promName = res.data.promName;
          _this.filters.searchKeyword = res.data.searchKeyword;
          _this.filters.budget = res.data.budget;
          _this.filters.warningNum = res.data.warningNum;
          _this.filters.frontPromType = res.data.frontPromType;
          _this.filters.foldingFlag = res.data.foldingFlag;
          _this.filters.overLimitRule = res.data.overLimitRule;
          _this.filters.description = res.data.description;
          _this.filters.channelCodes = res.data.channelCodes;
          _this.filters.proPlatform = (res.data.proPlatform + "").split("|");
          _this.filters.proUserType = res.data.proUserType + "";
          _this.filters.proMemberType = (res.data.proMemberType + "").split(
            "|"
          );
          _this.filters.storeArea = -1; //(res.data.storeArea + "").split("|");
          _this.filters.userArea = -1; //(res.data.userArea + "").split("|");
          _this.filters.startTime = res.data.startTime;
          _this.filters.endTime = res.data.endTime;
          _this.filters.remark = res.data.remark;
          _this.filters.rejectCouponsFlag = res.data.rejectCouponsFlag;
          _this.filters.parcelsFlag = res.data.parcelsFlag;
          _this.filters.promotionRules =
            res.data.promotionRules.length == 0
              ? [
                  {
                    conditionValue: null,
                    contentValue: null,
                    id: null,
                    level: 1
                  }
                ]
              : res.data.promotionRules;
          _this.filters.mainGiftSameFlag = res.data.mainGiftSameFlag;
          _this.filters.costAllocationFlag = parseInt(
            res.data.costAllocationFlag
          );
          _this.filters.templateFlag = res.data.templateFlag;
          _this.filters.status = res.data.status;
          // _this.filters.promotionStartEndTime[0] = new Date(res.data.startTime);
          // _this.filters.promotionStartEndTime[1] = new Date(res.data.endTime);
          _this.$set(_this.filters, "promotionStartEndTime", [
            new Date(res.data["startTime"]),
            new Date(res.data["endTime"])
          ]);
          _this.filters.labelId =
            res.data.labelId != null ? Number(res.data.labelId) : null;
          _this.filters.overlayAppFlag = res.data.overlayAppFlag;
          _this.filters.overlayAppNum = res.data.overlayAppNum;
          _this.filters.freightType = res.data.freightType;
          _this.filters.freightValue = res.data.freightValue;
          _this.filters.freightReducedValue = res.data.freightReducedValue;

          let selectMemTypes = [];
          res.data.memTypes.split(",").forEach(item=>{
            selectMemTypes.push(Number(item));
          });
          _this.selectMemTypes = selectMemTypes;
          if(selectMemTypes.length < 3){
            this.memTypeIsIndeterminate = true;
            this.memTypeCheckAll = false;
          }
          //新老用户
          let selectUserType = [];
          res.data.proUserType.split(",").forEach(item=>{
            selectUserType.push(Number(item));
          });
          _this.selectUserType = selectUserType;
          if(selectUserType.length < 2){
            this.userTypeIsIndeterminate = true;
            this.userTypeCheckAll = false;
          }
          //渠道
          let channelId = [];
          res.data.channelId.split(",").forEach(item=>{
            channelId.push(Number(item));
          });
          _this.channelId = channelId;
          if(channelId.length < 3){
            this.channelIdIsIndeterminate = true;
            this.channelIdCheckAll = false;this.channelId
          }
        } else {
          // alert("获取促销详情失败");
        }
      });
    },
    resetStoreForm() {
      this.resetForm("storeForm");
      this.storeFormFind();
    },
    resetProductForm() {
      this.resetForm("productForm");
      this.productFormFind();
    },
    resetMerchantForm() {
      this.resetForm("merchantForm");
      this.merchantFormFind();
    },
    addAllProduct() {
      let that_ = this;
      // this.productForm.storeIds = this.storeTableData.map((ele, index) => {
      //   return ele.id;
      // });
      let callback = function(res) {
        if (res.code == "0000") {
          that_.dialogVisibleTwo = false
          // 成功查询本地促销商品
          that_.getProductListV2(0, null);
          that_.getMutexProductList();
        }
      };
      this.productForm.promotionId = this.filters.id;
      marketRequest.promotionMerchantProductAddAll(this.productForm, callback);
    },

    getCurrentStep() {
      return this.active - 1;
    },
    changeContentValue(row) {
      // var reg = /^(?!0(\.0{1,2})?$)(\d(\.\d{1,2})?|10)$/;
      // if(this.filters.frontPromType == 7 && !reg.test(row.contentValue)){
      //   row.contentValue = '';
      // }
    },
    resetMerchantProductSearch() {
      this.resetForm("merchantProductSearchForm");
      this.merchantProductSearch();
    },
    // 模板下载
    downloadTemplate() {
      window.location.href =
        this.utils.getHost() + "jic-market/resource/download?key=FULL";
    },
    // 批量删除
    batchDelProduct() {
      let ids = [];
      this.allProductData.forEach(function(item,index,array){
        //判断父下面是否全选
        if(item.typeOfProduct == '10' && item.isCheck){
          if(item.children && item.children.length > 0){
            let isCheckItems = item.children.filter(function (subItem, index) {
              return !subItem.isCheck;
            });
            if(!(isCheckItems && isCheckItems.length > 0)){
              ids.push(item.id);
            }
          }else{
            ids.push(item.id);
          }
        }else if(item.typeOfProduct == '20' && item.isCheck){
          ids.push(item.id);
        }
      });
      if (ids.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }

      this.$confirm('确认批量删除已选内容？', "提示", {
        type: "warning",
        closeOnClickModal: false,
      }).then(() => {
        let this_ = this;
        let callback = function(res) {
          if (res.code == "0000") {
            // 成功查询本地促销商品
            this_.getProductListV2(0, null);
          } else {
            this.$message({ message: "删除商品失败", type: "fail" });
          }
        };
        let param = {};
        param.ids = ids;
        marketRequest.promotionMerchantProductDeleteBatch(param, callback);
      }).catch(() => {});

    },

    resetStoreSearch() {
      this.resetForm("storeSearchForm");
      this.mainStoreTableDataFormFind();
    },
    storeSearch() {
      this.mainStoreTableDataFormFind();
    },

    resetMerchantSearch() {
      this.resetForm("merchantSearchForm");
      this.mainMerchantFormFind();
    },
    merchantSearch() {
      this.mainMerchantFormFind();
    },
    genDescriptionPlaceholder() {
    // <el-radio :label="12" class="form-radio m_r45 radioAlignment">第X件Y折</el-radio>
    //     <el-radio :label="13" class="form-radio m_r45 radioAlignment">第X件Y元</el-radio>
    //     <el-radio :label="14" class="form-radio radioAlignment">满X件Y折</el-radio>
      let placeholder = "";
      if (
        typeof this.filters.frontPromType == "undefined" ||
        this.filters.frontPromType == null
      ) {
        return "";
      }
      let suffix = this.filters.overlayAppFlag == 1 ? "，可享受n次" : "";
      let prefix = this.filters.overlayAppFlag == 1 ? "每" : "";
      if (this.filters.frontPromType == 12) {
        placeholder = prefix + "第x件y折" + suffix;
      } else if (this.filters.frontPromType == 13) {
        placeholder = prefix + "第x件y元" + suffix;
      } else {
        placeholder = prefix + "满x件y折" + suffix;
      }
      return placeholder;
    },
    handleCurrentChangeMerchantProductTableData(pageNum) {
      this.merchantProductSearchForm.start = pageNum;
      this.getProductListV2(0, null);
    },
    handleSizeChangeMerchantProductTableData(val) {
      this.merchantProductSearchForm.limit = val;
      this.getProductListV2(0, null);
    },
    /*
  备注无法编辑
 */
    changeRemark(val) {
      this.$forceUpdate();
    },
    merchantProductSearch() {
      this.getProductListV2(0, this.merchantProductSearchForm);
    },
    // setep3--start
    seeMoreDeatil(row) {
      this.$router.push(`/FullPromotionDetailNew?id=${row.promotionId}&auth=0`);
    },
    handleClickMerchantProduct(tab, event) {
      if (tab.label == "生效商品") {
        this.getProductListV2(0, null);
      } else {
        this.getProductListV2(1, null);
      }
    },
    //互斥查看更多
    seeMore(row) {
      this.mutexDetailDialogVisible = true;
      this.mutexPromotionTable = [
        {
          promotionId: 26,
          promName: "测试互斥活动1",
          mutexTime: "2019-09-26 14:28:31 - 2019-10-04 14:28:34",
          mutexChannel: "BBC",
          mutexStroeName: "张小二bbc店铺"
        },
        {
          promotionId: 27,
          promName: "测试互斥活动2",
          mutexTime: "2020-01-26 14:28:31 - 2020-02-28 19:45:11",
          mutexChannel: "BBC",
          mutexStroeName: "张小二店铺"
        }
      ];
      //TODO 调用接口获取互斥活动列表
    },
    batchSaveV2() {
      let this_ = this;
      this.dialogVisibleTwo = !this.dialogVisibleTwo;
      this.productPromotionListObject.productPromotionList.splice(
        0,
        this.productPromotionListObject.productPromotionList.length
      );
      for (let i = 0; i < this.productAddSelection.length; i++) {
        let temp = {};
        temp.promotionId = this.promotionId;
        temp.mpId = this.productAddSelection[i].id;
        temp.spuId = this.productAddSelection[i].id;
        this.productPromotionListObject.productPromotionList.push(temp);
      }
      let callback = res => {
        if (res.code == "0000") {
          // 查询本地促销商品
          this_.getProductListV2(0, null);
          this_.getMutexProductList();
        }
      };
      marketRequest.saveBatchV3(this.productPromotionListObject, callback);

      // let this_ = this;
      // this.dialogVisibleTwo = !this.dialogVisibleTwo;
      // this.productPromotionListObject.productPromotionList.splice(0,this.productPromotionListObject.productPromotionList.length);
      // for (let i = 0; i < this.productAddSelection.length; i++) {
      //   let temp = {};
      //   temp.promotionId = this.promotionId;
      //   temp.mpId = this.productAddSelection[i].id;
      //   this.productPromotionListObject.productPromotionList.push(temp);
      // }
      // let callback = res => {
      //   if (res.code == "0000") {
      //     // 查询本地促销商品
      //     this_.getProductListV2(0, null);
      //   }
      // };
      // marketRequest.saveBatchV2(this.productPromotionListObject, callback );
    },

    reloadMutexV2(row) {
      let this_ = this;
      let param = {
        mpId: row.mpId,
        promotionMerchantProductId: row.id,
        promotionId: this.promotionId
      };
      let callback = res => {
        if (res.code == "0000") {
          // 查询本地促销商品
          this_.getProductListV2(1, null);
        }
      };
      marketRequest.reloadMutexV2(param, callback);
    },
    getProductListV2(type, searchParm) {
      this.merchantProductTableDataLoading = true;
      let this_ = this;
      let callback = function(res) {
        //
        if (res.code == "0000") {
          this_.isAllProductChecked = false;
          this_.isIndeterminateProductCheck = false;
          if (type == 0 && res.data.total > 0) {
            this_.merchantProductTableData = res.data.rows;
            this_.merchantProductTableDataTotal = res.data.total;
            this_.merchantProductTotalCount = res.data.totalCount;
            this_.allProductData = getAllRow(this_.merchantProductTableData, [],this_.filters.costAllocationFlag);
          } else {
            this_.merchantProductTableData = [];
            this_.merchantProductTableDataTotal = 0;
            this_.merchantProductTotalCount = 0;
          }
        } else {
        }
        this_.$nextTick(() =>{
          this_.merchantProductTableDataLoading = false;
        })
      };
      this.merchantProductSearchForm.promotionId = this.promotionId;
      marketRequest.getProductListV3(this.merchantProductSearchForm, callback);

      // let this_ = this;
      // let callback = function(res) {
      //   //
      //   if (res.code == "0000") {
      //     if(res.data.total > 0){
      //       if(type == 0){
      //         this_.merchantProductTableData = res.data.rows;
      //         this_.merchantProductTableDataTotal = res.data.total;
      //       }else{
      //         this_.merchantProductTableDataMutex = res.data.rows;
      //       }
      //     }
      //   } else {
      //   }
      // };
      // this.merchantProductSearchForm.promotionId = this.promotionId;
      // marketRequest.getProductListV2(this.merchantProductSearchForm, callback);
    },
    // setep3--
    removePromotionRuleSet(index, val) {
      this.filters.promotionRules.splice(index, 1);
      if (this.promotionId != null && val.id != "undefined") {
        let callback = function(res) {
          if (res.code == "0000") {
          } else {
            //alert("修改失败");
          }
        };
        let param = {
          id: val.id,
          promotionId: this.promotionId
        };
        this.utils.request.promotionRuleDelete(param, callback);
      }
    },
    addPromotionRuleSet() {
      this.filters.promotionRules.push({
        level: this.filters.promotionRules.length + 1
      });
    },
    //更新价格或者限量-todo
    updatePriceOrLimit(val) {
      let total = 0;
      total += Number(val.merchantAllocationScale);
      total += Number(val.parentAllocationScale);
      if (total != 100) {
       this.$message({
             message: "平摊分摊和商户分摊之和必须等于100",
             type: "error"
       });
       return;
      }
      if (!this.checkProductLimits(val)) {
        return;
      }
      let callback = function(res) {
        if (res.code == "0000") {
          val.limitRuleId = res.data;
        } else {
          //alert("修改失败");
        }
      };
      let temp = {};
      temp.id = val.limitRuleId == 0 ? null : val.limitRuleId;
      temp.promotionId = val.promotionId;
      temp.promotionId = val.promotionId;
      temp.mpId = val.mpId;
      temp.channelStoreLimit = val.channelStoreLimit;
      temp.channelIndividualLimit = val.channelIndividualLimit;
      temp.promPrice = val.promPrice;
      temp.individualLimit = val.individualLimit;
      temp.channelMerchantLimit = val.channelMerchantLimit;
      temp.limitType = val.typeOfProduct == 10 ? 5 : 3; //5spu,3sku
      temp.orderLimit = val.orderLimit;
      temp.parentAllocationScale =  val.parentAllocationScale;
      temp.merchantAllocationScale = val.merchantAllocationScale;
      temp.stockLimit = val.stockLimit;
      marketRequest.promotionLimitRuleInsert(temp, callback);
    },
    //批量添加商品
    productSaveBatch() {
      this.dialogVisibleTwo = !this.dialogVisibleTwo;
      //
      //
      //
      this.productPromotionListObject.productPromotionList.splice(
        0,
        this.productPromotionListObject.productPromotionList.length
      );
      //
      //
      //

      for (let i = 0; i < this.productAddSelection.length; i++) {
        let temp = {};
        temp.promotionId = this.promotionId;
        temp.mpId = this.productAddSelection[i].id;
        temp.mpName = this.productAddSelection[i].chineseName; // 商品名称
        temp.merchantName = this.productAddSelection[i].name; //商家名称
        temp.storeName = this.productAddSelection[i].storeName; //店铺名称
        //temp.salePriceWithTax = this.productAddSelection[i].salePriceWithTax;  //零售价
        temp.mpCode = this.productAddSelection[i].code; //商品编码
        temp.mpParentId = this.productAddSelection[i].parentId;
        temp.merchantId = this.productAddSelection[i].merchantId;
        temp.categoryId = this.productAddSelection[i].categoryId;
        // temp.categoryName     = this.productAddSelection[i].categoryName;    类别名称
        temp.picUrl = this.productAddSelection[i].pictureUrl;
        this.productPromotionListObject.productPromotionList.push(temp);

        //
        //
        //
      }
      //
      // //
      //   "======================" +
      //     JSON.stringify(this.productPromotionListObject.productPromotionList)
      // );
      //

      let callback = res => {
        //
        if (res.code == "0000") {
          // 查询本地促销商品
          this.mainProductTableDataFormFind();
        }
      };

      this.utils.request.promotionMerchantProductSaveBatch(
        this.productPromotionListObject,
        callback
      );
    },
    productTableDataSubmit2() {
      //this.productSaveBatch();
      this.batchSaveV2();
    },
    //确定 选择商品
    productTableData2Click() {
      //
      // 调添加商品 接口
      this.productTableDataSubmit2();
    },
    // 选择商品
    addSelectionChangeProduct(val) {
      let this_ = this;
      this_.productAddSelection = val;
    },

    //修改table header的背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color:rgb(250,250,250);";
      }
    },
    //table的双色条纹
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    add() {
      this.dialogVisibleTwo = true;
      this.tableDataTwo = [];
      this.productFormFind();
    },
    // 商品方法开始
    productFormFind(start, limit) {
      if (start) {
        this.productForm.start = start;
      }
      if (limit) {
        this.productForm.limit = limit;
      }
      this.tableDataTwoLoading = true;
      let that_ = this;
      this.productForm.storeIds = this.storeTableData.map((ele, index) => {
        return ele.storeId;
      });
      // 点击搜索时,从第一页开始
      this.productForm.promotionId = this.filters.id;
      marketRequest.promotionSpuPageByPromotionId(this.productForm, function(
        resp
      ) {
        if (resp.code == "0000") {
          if(resp.data.rows == null || resp.data.rows.length < 1){
            that_.tableDataTwo = [];
            that_.productListTotal = 0;
          }else{
            that_.tableDataTwo = resp.data.rows.map((ele, index) => {
                let spu = {};
                spu.id = ele.id;
                spu.code = ele.code;
                spu.chineseName = ele.chineseName;
                spu.totalStock = ele.totalStock;
                spu.goodsCategory = ele.fullNamePath;
                spu.merchantName = ele.merchantName;
                spu.storeName = ele.storeName;
                spu.salePriceScope = ele.salePriceWithTax;
                // spu.measureUnit = ele.measureUnit;
                return spu;
              });
              that_.productListTotal = Number(resp.data.total);
          }
          that_.$nextTick(() =>{
            that_.tableDataTwoLoading = false;
          })
        }
      });
      // let that_ =this;
      // that_.utils.request.queryshopApi(this.productForm, function (resp) {
      //   if (resp.code == "0000") {
      //     that_.tableDataTwo= resp.data.rows;
      //     that_.productListTotal= resp.data.total;
      //   }
      //
      //   that_.tableDataTwo= resp.data.rows;
      // });
    },
    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    // setep3--end

    shenheHuodong(flag) {
      let _this = this;
      if (flag == 0) {
        this.$confirm("确认提交审核？", "提示", {
          type: "warning"
        })
          .then(() => {
            let callback = res => {
              if (res.code == "0000") {
                _this.filters.status = 2;
              }
            };
            let param = {};
            param.id = this.promotionId;
            param.status = 2;
            this.utils.request.promotionUpdate(param, callback);
          })
          .catch(() => {});
      } else {
        this.dialogVisibleAdmin = true;
      }
    },
    detailList() {
      this.$router.push({
        path: `/pages/promotionManagement/XofferPromotion`
      });
    },
    submitFormAdminNotPass() {
      this.$refs.adminDataForm.validate(auditRemarkE => {
        if (auditRemarkE) {
          let _this = this;
          let callback = res => {
            if (res.code == "0000") {
              _this.dialogVisibleAdmin = false;
              _this.filters.status = 4;
              _this.auditCount = 1;
            }
          };
          this.adminDataForm.id = this.promotionId;
          this.adminDataForm.status = 4;
          this.utils.request.promotionUpdate(this.adminDataForm, callback);
        }
      });
    },
    submitFormAdmin() {
      let _this = this;
      let callback = res => {
        if (res.code == "0000") {
          _this.dialogVisibleAdmin = false;
          _this.filters.status = 11;
        }
      };
      this.adminDataForm.id = this.promotionId;
      this.adminDataForm.status = 11;
      this.utils.request.promotionUpdate(this.adminDataForm, callback);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    //---------------------------店铺------------------------------------------------start
    //查询店铺
    storeFormFind() {
      this.storeTableData2Loading = true;
      //商家 取出商家id-->merchantId
      // this.merchantTableData2;

      let ids = this.merchantTableData2.map(item => item.merchantId).toString();

      //
      //
      //
      //

      let params = [];
      //
      let idArray = (ids + "").split(",");
      //
      //

      for (var i = 0; i < idArray.length; i++) {
        params.push({ id: idArray[i] });
      }

      //
      //
      //

      //
      //
      //

      // mergeTo = mergeTo.concat(mergeFrom);

      if (this.merchantTableData2.length == 0) {
        this.$message({ message: "请先选择商家", type: "success" });
      }

      // this.merchantTableDataTatol;
      this.storeTableData2.splice(0, this.storeTableData2.length);
      var this__ = this;
      this.storeForm.merchantIds = ids;
      this.utils.request.queryByIds(this.storeForm, function(res) {
        //
        if (res.code == "0000") {
          // this__.storeTableData2= this__.storeTableData2.concat(res.data);
          this__.storeTableData2 = res.data.rows;
          this__.merchantTableDataTatolStore = res.data.total;
        }
        this__.$nextTick(() =>{
          this__.storeTableData2Loading = false;
        })
      });
    },
    storeTableDataselectionChange(val) {
      this.storeTableDataSelection = val;
    },
    merchantTableData2selectionChange(val) {
      this.merchantTableData2Selection = val;
    },
    //选择店铺
    storeTableData2AddSelectionChange(val) {
      this.addSelectionStoreTableData2 = val;
    },
    //确定 选择店铺
    storeTableData2Click() {
      // 调添加店铺 关系接口
      this.merchantTableDataSubmit2();
    },
    merchantTableDataSubmit2() {
      this.storeSaveBatch();

      let callback = res => {
        //
        if (res.code == "0000") {
          this.storeSaveBatch();
        }
      };

      //调接口
      //删除这个活动老的数据
      //批量添加新的数据
      // this.promotion.id=null;
      // this.promotion.promotionId=this.promotionId;
      // this.promotion.merchantType="2";
      //this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
    },

    //批量添加店铺
    storeSaveBatch() {
      let flag = true;
      // this.storeTableData.forEach(res=>{
      //   this.addSelectionStoreTableData2.forEach(item=>{
      //     if(res.storeId == item.id){
      //       this.$message({ message: "不能添加重复店铺", type: "error" });
      //       flag = false;
      //     }
      //   })
      // });
      if (!flag) {
        return;
      }
      this.pomotionListObject.pomotionList.splice(
        0,
        this.pomotionListObject.pomotionList.length
      );

      for (var i = 0; i < this.addSelectionStoreTableData2.length; i++) {
        var temp = {};

        temp.promotionId = this.promotionId;
        temp.storeId = this.addSelectionStoreTableData2[i].id;
        temp.merchantType = "2";
        temp.storeName = this.addSelectionStoreTableData2[i].storeName;
        temp.storeCode = this.addSelectionStoreTableData2[i].storeCode;
        temp.storeType = this.addSelectionStoreTableData2[i].storeType;
        temp.merchantId = this.addSelectionStoreTableData2[i].merchantId;
        temp.merchantName = this.addSelectionStoreTableData2[i].merchantName;
        temp.orgNumber = this.addSelectionStoreTableData2[i].orgNumber;
        this.pomotionListObject.pomotionList.push(temp);
      }

      let callback = res => {
        //
        if (res.code == "0000") {
          this.mainStoreTableDataFormFind();
        }
      };

      this.utils.request.promotionMerchantSaveBatch(
        this.pomotionListObject,
        callback
      );
    },
    //查询绑定关系的店铺
    mainStoreTableDataFormFind() {
      this.storeTableDataLoading = true;
      // this.storeTableData
      this.storeSearchForm.merchantType = "2";
      this.storeSearchForm.promotionId = this.promotionId;
      var this__ = this;
      this.utils.request.promotionMerchantList(this.storeSearchForm, function(
        res
      ) {
        if (res.code == "0000") {
          var ret = [];
          for (var i = 0; i < res.data.list.length; i++) {
            var temp = {};
            temp.promotionId = res.data.list[i].promotionId;
            temp.id = res.data.list[i].id;
            temp.storeId = res.data.list[i].storeId;
            temp.storeName = res.data.list[i].storename;
            temp.storeCode = res.data.list[i].storecode;
            temp.storeType = res.data.list[i].storeType;

            ret.push(temp);
          }
          //店铺调试
          this__.storeTableData = res.data.list;
          this__.storeTableDataTatol = res.data.totalCount;
        }
        this__.$nextTick(() =>{
          this__.storeTableDataLoading = false;
        })
      });
    },

    // 换页刷新
    mainSroreMerchantRefreshPageRequest: function(pageNum) {
      this.mainStoreMerchantForm.pageNo = pageNum;
      this.mainStoreTableDataFormFind();
    },
    // 换页刷新
    mainSroreMerchantHandleSizeChange: function(pageSize) {
      this.mainStoreMerchantForm.pageNo = 1;
      this.mainStoreMerchantForm.pageSize = pageSize;
      this.mainStoreTableDataFormFind();
    },

    // 换页刷新
    refreshPageRequestStore: function(pageNum) {
      this.merchantFormStore.start = pageNum;
      // this.merchantFormFind();
      this.storeFormFind();
    },
    // 换页刷新
    handleSizeChangeStore: function(pageSize) {
      this.merchantForm;
      this.merchantFormStore.limit = pageSize;
      this.merchantFormStore.start = 1;
      this.storeFormFind();
    },

    //---------------------------店铺------------------------------------------------end

    //---------------------------商家------------------------------------------------start

    //---------------------------分页------------------------------------------------start
    // 换页刷新
    refreshPageRequest: function(pageNum) {
      this.merchantForm.start = pageNum;
      this.merchantFormFind();
    },
    // 换页刷新
    handleSizeChange: function(pageSize) {
      this.merchantForm.limit = pageSize;
      this.merchantForm.start = 1;
      this.merchantFormFind();
    },
    producthandleCurrentChange(pageNum) {
      this.productForm.start = pageNum;
      this.productFormFind();
    },
    // 换页刷新
    mainMerchantRefreshPageRequest: function(pageNum) {
      this.mainMerchantForm.pageNo = pageNum;
      this.mainMerchantFormFind();
    },
    producthandleSizeChange(pageSize) {
      this.productForm.start = 1;
      this.productForm.limit = pageSize;
      this.productFormFind();
    },
    // 换页刷新
    mainMerchantHandleSizeChange: function(pageSize) {
      this.mainMerchantForm.pageNo = 1;
      this.mainMerchantForm.pageSize = pageSize;
      this.mainMerchantFormFind();
    },
    //查询绑定关系的商家
    mainMerchantFormFind() {
      this.merchantTableData2Loading = true;
      this.merchantSearchForm.merchantType = "1";
      var this__ = this;
      this.merchantSearchForm.promotionId = this.promotionId;
      this.utils.request.promotionMerchantList(
        this.merchantSearchForm,
        function(res) {
          if (res.code == "0000") {
            var ret = [];
            for (var i = 0; i < res.data.list.length; i++) {
              var temp = {};
              temp.id = res.data.list[i].id;
              temp.name = res.data.list[i].merchantName;
              temp.orgNumber = res.data.list[i].orgNumber;
              temp.merchantType = res.data.list[i].merchantTypeManager;
              temp.merchantId = res.data.list[i].merchantId;
              ret.push(temp);
            }
            this__.merchantTableData2 = ret;
            this__.mainMerchantTableDataTatol = res.data.totalCount;
          }
          this__.$nextTick(() =>{
            this__.merchantTableData2Loading = false;
          })
        }
      );
    },
    // 删除店铺
    storeDelete(id) {
      // this.$confirm("是否确认删除？", "提示", {
      //   type: "warning",
      //   closeOnClickModal: false
      // })
      //   .then(() => {
          let callback = res => {
            this.mainStoreTableDataFormFind();
            if (res.code == "0000" && res.data == "1") {
              //删除成功再调分页
              this.$message({ message: "删除成功", type: "success" });
            } else {
              this.$message({ message: "操作失败, " + res.msg, type: "error" });
            }
          };
          this.promotion.id = id;
          this.utils.request.promotionMerchantDeleteById(
            this.promotion,
            callback
          );
        // })
        // .catch(() => {});
    },

    //---------------------------分页------------------------------------------------end
    //删除商家
    merchantTableData2delete(id) {
      // this.$confirm("是否确认删除？", "提示", {
      //   type: "warning",
      //   closeOnClickModal: false
      // })
      //   .then(() => {
          let callback = res => {
            this.mainMerchantFormFind();
            this.mainStoreTableDataFormFind();
            if (res.code == "0000" && res.data == "1") {
              //删除成功再调分页
              this.$message({ message: "删除成功", type: "success" });
            } else {
              this.$message({ message: "操作失败, " + res.msg, type: "error" });
            }
          };
          this.promotion.id = id;
          this.utils.request.promotionMerchantDeleteById(
            this.promotion,
            callback
          );
        // })
        // .catch(() => {});
    },
    //选择商家
    addSelectionChange(val) {
      this.addSelection = val;
      //
    },
    //提交 选择商家
    merchantTableDataSubmit() {
      this.promotionMerchantSaveBatch();
      //this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
    },
    promotionMerchantSaveBatch() {
      let flag = true;
      // this.merchantTableData2.forEach(res=>{
      //   this.addSelection.forEach(item=>{
      //     //  ;
      //     if(res.merchantId == item.id){
      //       this.$message({ message: "不能添加重复商家", type: "error" });
      //       flag = false;
      //     }
      //   })
      // });
      if (!flag) {
        return;
      }
      //
      //
      //
      this.pomotionListObject.pomotionList.splice(
        0,
        this.pomotionListObject.pomotionList.length
      );
      //
      //
      //

      for (var i = 0; i < this.addSelection.length; i++) {
        var temp = {};

        temp.promotionId = this.promotionId;
        temp.merchantId = this.addSelection[i].id;
        temp.merchantType = "1";
        temp.merchantName = this.addSelection[i].name;
        temp.merchantTypeManager = this.addSelection[i].merchantType;
        temp.orgNumber = this.addSelection[i].orgNumber;
        temp.name = this.addSelection[i].name;

        this.pomotionListObject.pomotionList.push(temp);
      }
      //
      //
      //

      let callback = res => {
        //
        if (res.code == "0000") {
          this.mainMerchantForm.merchantType = "1";
          this.mainMerchantFormFind();
        }
      };

      var this__ = this;
      this.utils.request.promotionMerchantSaveBatch(
        this.pomotionListObject,
        callback
      );
    },
    //查询商家
    merchantFormFind() {
      this.merchantTableDataLoading = true;
      var this__ = this;
      //只有运营平台有使用渠道
      if (this.deptType == 0 && this.filters.channelCodes) {
        this.merchantForm.childIds = this.filters.channelCodes.split(',').map(item => item);
        // this.merchantForm.childIds = this.$refs.channelTree.getCheckedKeys();
      }
      this.utils.request.queryMerchantList(this.merchantForm, function(res) {
        // this.utils.request.queryMerchantListOther(null, function (res) {
        if (res.code == "0000") {
          this__.merchantTableData = res.data.rows;
          this__.merchantTableDataTatol = res.data.total;
        }
        this__.$nextTick(() =>{
          this__.merchantTableDataLoading = false;
        })
      });
    },
    //---------------------------商家------------------------------------------------end

    //活动渠道
    handleCheckAllChange(val) {
      this.filters.channelCodes = val
        ? chanelCodesRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.chanelCodesRadios.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.chanelCodesRadios.length;
    },
    //活动平台
    handleCheckAllChange1(val) {
      this.filters.proPlatform = val
        ? proPlatformRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate1 = false;
    },
    handleCheckedCitiesChange1(value) {
      let checkedCount = value.length;
      this.checkAll1 = checkedCount === this.proPlatformRadios.length;
      this.isIndeterminate1 =
        checkedCount > 0 && checkedCount < this.proPlatformRadios.length;
    },

    //新老用户
    handleCheckAllChange2(val) {
      this.filters.proUserType = val
        ? proUserTypeRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate2 = false;
    },
    handleCheckedCitiesChange2(value) {
      let checkedCount = value.length;
      this.checkAll2 = checkedCount === this.proUserTypeRadios.length;
      this.isIndeterminate2 =
        checkedCount > 0 && checkedCount < this.proUserTypeRadios.length;
    },
    //会员类型
    handleCheckAllChange3(val) {
      this.filters.proMemberType = val
        ? proMemberTypeRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate3 = false;
    },
    handleCheckedCitiesChange3(value) {
      let checkedCount = value.length;
      this.checkAll3 = checkedCount === this.proMemberTypeRadios.length;
      this.isIndeterminate3 =
        checkedCount > 0 && checkedCount < this.proMemberTypeRadios.length;
    },
    //会员等级
    handleCheckAllChange4(val) {
      this.filters.proMemberLevel = val
        ? proMemberLevelRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate4 = false;
    },
    handleCheckedCitiesChange4(value) {
      let checkedCount = value.length;
      this.checkAll4 = checkedCount === this.proMemberLevelRadios.length;
      this.isIndeterminate4 =
        checkedCount > 0 && checkedCount < this.proMemberLevelRadios.length;
    },
    //添加商家
    querySupplierListForAdd() {
      this.editDialogVisible = true;
      this.promotion.merchantType = 1;
      this.merchantTableData = [];
      this.merchantFormFind();
    },
    //添加店铺
    querySupplierListForAdd2() {
      this.editDialogVisible2 = true;
      this.promotion.merchantType = 2;
      this.storeTableData2 = [];
      this.storeFormFind();
    },
    delAllSelectedSupplierstoreTableData() {
      if (this.storeTableDataSelection.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }
      this.$confirm('确认批量删除已选内容？', "提示", {
        type: "warning",
        closeOnClickModal: false,
      }).then(() => {
        let ids = this.storeTableDataSelection.map(item => item.id).toString();
        let idArray = (ids + "").split(",");
        this.delAllSelectedSupplierstoreTableDataQueryList(idArray);
      }).catch(() => {});

    },
    delAllSelectedSupplierstoreTableDataQueryList(idArray) {
      let that = this;
      this.promotion.merchantType = "2";
      this.promotion.id = idArray[this.storeTableDataSelectionIndex];
      this.utils.request.promotionMerchantDeleteById(
        this.promotion,
        function() {
          that.storeTableDataSelectionIndex++;
          if (that.storeTableDataSelectionIndex < idArray.length) {
            that.delAllSelectedSupplierstoreTableDataQueryList(idArray);
          } else {
            //执行成功
            that.storeTableDataSelectionIndex = 0;
            that.$message({ message: "删除成功", type: "success" });
            that.mainStoreTableDataFormFind();
          }
        }
      );
    },
    //批量删除商家
    delAllSelectedSuppliermerchantTableData2() {
      if (this.merchantTableData2Selection.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }
      this.$confirm('确认批量删除已选内容？', "提示", {
        type: "warning",
        closeOnClickModal: false,
      }).then(() => {
        let ids = this.merchantTableData2Selection
          .map(item => item.id)
          .toString();
        let idArray = (ids + "").split(",");
        this.delAllSelectedSupplierQueryList(idArray);
      }).catch(() => {});


    },
    delAllSelectedSupplierQueryList(idArray) {
      let that = this;
      this.promotion.merchantType = "1";
      this.promotion.id = idArray[this.merchantTableData2SelectionIndex];
      this.utils.request.promotionMerchantDeleteById(
        this.promotion,
        function() {
          that.merchantTableData2SelectionIndex++;
          if (that.merchantTableData2SelectionIndex < idArray.length) {
            that.delAllSelectedSupplierQueryList(idArray);
          } else {
            //执行成功
            that.merchantTableData2SelectionIndex = 0;
            that.$message({ message: "删除成功", type: "success" });
            that.mainMerchantFormFind();
            that.mainStoreTableDataFormFind();
          }
        }
      );
    },

    // ------------------------------------商品开始方法-------------------------------------start

    // 换条数刷新
    handleSizeChangeForProduct: function(pageSize) {
      this.productForm.limit = pageSize;
      this.productForm.start = 1;
      this.productFormFind();
    },

    // 换页刷新
    handleCurrentChangeForProduct: function(pageNum) {
      this.productForm.start = pageNum;
      this.productFormFind();
    },
    //
    // // 查询商品
    // productFormFind(){
    //   let that_ =this;
    //   that_.utils.request.queryPageProductManagement(this.productForm, function (resp) {
    //     //
    //     if (resp.code == "0000") {
    //       that_.productTableData= resp.data.rows;
    //       that_.productTableDataTotal = resp.data.total;
    //     }
    //   });
    // },

    // 商品多项目选择
    productSelectionChange(val) {
      //
      // this.storeTableDataSelection=val;
    },

    // // 选择商品
    // addSelectionChangeProduct(val) {
    //   let this_ = this;
    //   this_.productAddSelection = val;
    //   //
    // },

    // //确定 选择商品
    // productTableData2Click(){
    //   //
    //   // 调添加商品 接口
    //   this.productTableDataSubmit2();
    // },
    // productTableDataSubmit2(){
    //
    //   this.productSaveBatch();
    //   // let callback = res => {
    //   //   //
    //   //   if (res.code == "0000") {
    //   //     this.productSaveBatch();
    //   //   }
    //   // };
    //   //
    //   // //调接口
    //   // //删除这个活动老的数据
    //   // //批量添加新的数据
    //   // this.promotion.id=null;
    //   // this.promotion.promotionId=this.promotionId;
    //   // this.promotion.merchantType="2";
    //   // //  TODO 下面可以不用删除
    //   // this.utils.request.promotionMerchantDeleteByPromotionId(this.promotion, callback);
    // },

    //批量添加商品
    // productSaveBatch(){
    //
    //
    //
    //   this.productPromotionListObject.productPromotionList.splice(0,this.productPromotionListObject.productPromotionList.length);
    //
    //
    //
    //
    //   for (var i = 0; i < this.productAddSelection.length; i++) {
    //     var temp = {};
    //     temp.promotionId         = this.promotionId;
    //     temp.mpId           =  this.productAddSelection[i].id;
    //     temp.mpName         =  this.productAddSelection[i].chineseName; // 商品名称
    //     temp.merchantName         =  this.productAddSelection[i].name;  //商家名称
    //     temp.mpCode         =  this.productAddSelection[i].code;  //商品编码
    //     temp.mpParentId       = this.productAddSelection[i].parentId;
    //     temp.merchantId       = this.productAddSelection[i].merchantId;
    //     temp.categoryId        = this.productAddSelection[i].categoryId;
    //     // temp.categoryName     = this.productAddSelection[i].categoryName;    类别名称
    //     temp.picUrl        = this.productAddSelection[i].pictureUrl;
    //     this.productPromotionListObject.productPromotionList.push(temp);
    //   }
    //
    //
    //
    //
    //   let callback = res => {
    //
    //     if (res.code == "0000") {
    //       // 查询本地促销商品
    //       this.mainProductTableDataFormFind();
    //     }
    //   };
    //
    //   this.utils.request.promotionMerchantProductSaveBatch(this.productPromotionListObject, callback );
    //
    // },

    //查询促销商品
    mainProductTableDataFormFind() {
      this.mainProductForm.promotionId = this.promotionId;
      let this_ = this;
      this.utils.request.promotionMerchantProductList(
        this.mainProductForm,
        function(res) {
          //
          if (res.code == "0000") {
            // let ret = [];
            // for (let i = 0; i < res.data.list.length; i++) {
            //   var temp = {};
            //   temp.mpCode          = res.data.list[i].mpCode;
            //   temp.productName                   = res.data.list[i].mpName;
            //   temp.barcode              = res.data.list[i].barcode;
            //   // temp.unit            = res.data.list[i].unit;
            //   temp.merchantName            = res.data.list[i].merchantName;
            //   ret.push(temp);
            // }
            //
            this_.merchantProductTableData = res.data.rows;
            this_.merchantProductTableDataTotal = res.data.total;
          }
        }
      );
    },

    // ------------------------------------商品结束方法-------------------------------------end

    addActive() {
      if(parseInt(this.active) == 1){
        this.active = parseInt(this.active)  + 2;
      }else{
        this.active = parseInt(this.active)  + 1;
      }
      this.$router.push({ query: { id: this.promotionId ,auth:0,active:this.active} })
      if (this.active > 4) {
        this.$router.push({
          path: "/pages/promotionManagement/XofferPromotion"
        });
      }
    },
    back() {

      if(parseInt(this.active) == 3){
        this.active = parseInt(this.active) - 2;
      }else{
        this.active = parseInt(this.active) - 1;
      }
      this.$router.push({ query: { id: this.promotionId ,auth:0,active:this.active} })
      this.nextOrBack();
    },
    next() {
      let _this = this;
      let callback = function(res) {
        if (res.code == "0000") {
          _this.promotionId = res.data;
          _this.filters.id = res.data;
          _this.promotion.promotionId = res.data;
          _this.mainMerchantForm.promotionId = res.data;
          _this.mainStoreMerchantForm.promotionId = res.data;
          _this.getProductListV2(0, null);
          _this.getMutexProductList();
          // _this.getPromotionStoreTableData();
          _this.addActive();

        }
      };
      let callbackUpdate = function(res) {
        if (res.code == "0000") {
          _this.getProductListV2(0, null);
          _this.getMutexProductList();
          // _this.getPromotionStoreTableData();
          _this.addActive();
        }
      };
      //保存活动基础配置
      if (this.active == 1) {
        this.$refs["filters"].validate(valid => {
          if (valid) {
            //当前登录用户身份为母平台校验所属渠道

            //非母平台清除子平台编码
             if (this.dataForm.channelCodes) {
                        delete this.dataForm.channelCodes;
                    }

            this.filters.startTime = this.filters.promotionStartEndTime[0];
            this.filters.endTime = this.filters.promotionStartEndTime[1];
            if (this.deptType == 3) {
              this.filters.costAllocationFlag = 1;
              this.filters.storeAllocationScale = 100;
            }
            //保存会员等级 会员类型
            this.filters.memTypes = this.selectMemTypes.join(",")
            this.filters.proUserType = this.selectUserType.join(",");
            this.filters.channelId = this.channelId.join(",");
            if (this.promotionId == null) {
              if( new Date(this.filters.startTime) < new Date()){
                this.$message({
                  message: "开始时间不能小于当前时间,请修改活动时间"
                });
                return;
              }
              this.utils.request.promotionCreate(this.filters, callback);
            } else {
              if (
                this.filters.status == 9 &&
                new Date(this.filters.startTime) < new Date()
              ) {
                this.$message({
                  message: "草稿状态下开始时间不能小于当前时间,请修改活动时间"
                });
              } else {
                this.utils.request.promotionUpdate(
                  this.filters,
                  callbackUpdate
                );
              }
            }
          }
        });
      }
      //更新活动状态
      if (this.active == 3) {
        if (this.active == 3 && this.merchantProductTableData.length == 0) {
          _this.$message({ message: "商品未添加", type: "fail" });
          return;
        }
        for (let i = 0; i < this.merchantProductTableData.length; i++) {
          if (!this.checkProductLimits(this.merchantProductTableData[i])) {
            return;
          }
          if (this.merchantProductTableData[i].children.length > 0) {
            for (
              var j = 0;
              j < this.merchantProductTableData[i].children.length;
              j++
            ) {
              if (
                !this.checkProductLimits(
                  this.merchantProductTableData[i].children[j]
                )
              ) {
                return;
              }
            }
          }
        }
        if (this.filters.status == 9) {
          let callback = function(res) {};
          this.filters.status = 1;
          this.utils.request.promotionUpdateStatus(this.filters, callback);
        }
        this.addActive();
      }

      if (this.active == 2) {
        if (
          this.storeTableData.length == 0 ||
          this.merchantTableData2.length == 0
        ) {
          //判断商家店铺
          // _this.$message({ message: "商家或店铺未添加", type: "fail" });
          // return;
        }
        this.getProductListV2(0, null);
        this.getMutexProductList();
        this.getPromotionStoreTableData();
        this.addActive();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //批量选择删除商品
    handleBatchDeleteSelection(val) {
      this.batchDeleteSelection = val.map(item => {
        return item.id;
      });
    },
    //批量删除商品-todo
    delBatchMerchantProducts(ids) {
      let callback = function(res) {
        if (res.code == "0000") {
          //成功后重新获取一下商家商品列表
        } else {
          alert("删除失败");
        }
      };
      let param = { ids: ids };
      this.utils.request.promotionMerchantProductDeleteBatch(param, callback);
    },

    //删除促销商品-todo
    delMerchantProducts(id) {
      // this.$confirm("是否确认删除活动？", "提示", {
      //   type: "warning",
      //   closeOnClickModal: false
      // })
      //   .then(() => {
          let this_ = this;
          let callback = function(res) {
            if (res.code == "0000") {
              // 成功查询本地促销商品
              this_.getProductListV2(0, null);
            } else {
              this_.getProductListV2(0, null);
              alert("删除失败");
            }
          };
          let param = {};
          param.id = id;
          marketRequest.promotionMerchantProductDelete(param, callback);
        // })
        // .catch(() => {});

      // this.$confirm("是否确认删除活动？", "提示", {
      //   type: "warning"
      // })
      //   .then(() => {
      //     let this_ =this;
      //     let callback = function(res) {
      //       if (res.code == "0000") {
      //         // 成功查询本地促销商品
      //         this_.mainProductTableDataFormFind();
      //       } else {
      //         this_.mainProductTableDataFormFind();
      //         alert("删除失败");
      //       }
      //     };
      //     let param ={};
      //     param.promotionId         =promotionId;
      //     param.mpId           =mpId;
      //     this.utils.request.promotionMerchantProductDelete(param, callback);
      //   })
      //   .catch(() => {
      //   });
    },

    // //更新价格或者限量-todo
    // updatePriceOrLimit(val){
    //
    //   let callback = function(res) {
    //     if (res.code == "0000") {
    //
    //     } else {
    //       //alert("修改失败");
    //     }
    //   };
    //   this.utils.request.promotionMerchantProductUpdatePriceOrLimit(val, callback);
    // },
    repelSelectionChange(val) {
      this.repelSelection = val;
    },
    createPage() {
      this.$router.push("/CreatePromotion");
    },
    handleClick(tab, event) {
      //
      if (tab.name == "0") {
        // 触发‘配置管理’事件
        this.first();
      } else {
        // 触发‘用户管理’事件
        this.second();
      }
    },
    first() {
      //
      this.modalShow = 1;
    },
    second() {
      //
      this.modalShow = 2;
    },
    //添加商品弹窗
    productSelectionModal() {
      this.productVisible = true;
    },
    showBatchSetUp() {
      if (this.search == true) {
        this.search = false;
      }
      if (this.setUp == false) {
        this.setUp = true;
      } else if (this.setUp == true) {
        this.setUp = false;
      }
    },
    showQueryCondition() {
      if (this.setUp == true) {
        this.setUp = false;
      }
      if (this.search == false) {
        this.search = true;
      } else if (this.search == true) {
        this.search = false;
      }
    },
    batchReAdd() {
      if (this.multipleSelection.length < 1) {
        this.$message({ message: "请选择要设置的商品", type: "error" });
        return false;
      }
      this.$message({ message: "操作成功", type: "success" });
    },
    updatePriceAndLimit() {},
    importCommodityModal(val) {
      if (val === 1) {
        this.operation = true;
      } else if (val == 2) {
        this.operation = false;
      }
      this.uploadVisible = true;
    },
    // 取值
    getValue(value) {
      this.valueId = value;
      //
    },
    handleCheckChange(data, checked, indeterminate) {
      //
      //
    },
    handleClose() {
      //
    },
    /**
     * 点击活动名称跳转详情
     */
    linkInfoByMutexProduct(promotionId, type) {
      if(type == 1){
        this.$router.push({ path: "/SinglePromotionDetail/" + promotionId + "/0"});
        //this.$router.push(`/SinglePromotionDetail?id=${promotionId}&auth=0`);
      }else if(type == 2){
        this.$router.push(`/FullNumPromotionDetailNew?id=${promotionId}&auth=0`);
      }else if(type == 3){
        this.$router.push({ path: "/FullPromotionDetailNew/" + promotionId + "/0"});
        //this.$router.push(`/FullPromotionDetailNew?id=${promotionId}&auth=0`);
      }else if(type == 4){
        this.$router.push(`/SeckillDetail?promotionId=${promotionId}`);
      }else if(type == 5){
        this.$router.push({ path: "/GiftPromotionDetail/" + promotionId + "/0"});
        //this.$router.push(`/GiftPromotionDetail?id=${promotionId}&auth=0`);
      }else if(type == 6){
        this.$router.push({ path: "/ComplexPromotionInfo/" + promotionId});
      }else if(type == 7){
        this.$router.push({ path: "/XofferPromotionDetail/" + promotionId + "/0"});
        //this.$router.push(`/XofferPromotionDetail?id=${promotionId}&auth=0`);
      }else if(type == 8){
        this.$router.push({ path: "/IncreasePromotionDetail/" + promotionId + "/0"});
        //this.$router.push(`/IncreasePromotionDetail?id=${promotionId}&auth=0`);
      }else if(type == 9){
        this.$router.push(`/QueryPresellPromotion?value=${promotionId}&auth=0`);
      }else if(type == 10){
        this.$router.push("/GroupDetailPromotion?id=" + `${promotionId}`);
      }else if(type == 12){
        this.$router.push(`/QueryPromotion?value=${promotionId}&auth=0`);
      }
    },
    nextOrBack(){
      //根据当前url中active参数判断执行第几步方法
      if (this.active){
        if(parseInt(this.active) == 3){
          this.$nextTick(()=>{
            this.getProductListV2(0, null);
            this.getMutexProductList();
            this.getPromotionStoreTableData();
          })

        }
      }
    },
    handleCheckedAllChange(value) {
      //
      this.isIndeterminateCheck = false;

      this.allData.forEach(f => {
        f.isCheck = value;
        f.isIndeterminateCheck = false;
      });
    },
    handleCheckedChange(row, checked) {
      //
      if (row.isIndeterminateCheck) {
        row.isCheck = true;
        checked = true;
      }
      row.isIndeterminateCheck = false;

      changeChild(row, checked);
      changeParent(row, this.allData);

      this.isAllChecked = this.allData.every(e => {
        return e.isCheck;
      });

      this.isIndeterminateCheck =
        !this.isAllChecked &&
        this.allData.some(e => {
          return e.isCheck;
        });
    },

    handleCheckedAllProductChange(value) {
      //
      this.isIndeterminateProductCheck = false;

      this.allProductData.forEach(f => {
        f.isCheck = value;
        f.isIndeterminateCheck = false;
      });
    },
    handleCheckedProductChange(row, checked) {
      //
      if (row.isIndeterminateCheck) {
        row.isCheck = true;
        checked = true;
      }
      row.isIndeterminateCheck = false;

      changeChild(row, checked);
      changeParent(row, this.allProductData);

      this.isAllProductChecked = this.allProductData.every(e => {
        return e.isCheck;
      });

      this.isIndeterminateProductCheck =
        !this.isAllProductChecked &&
        this.allProductData.some(e => {
          return e.isCheck;
        });
    },
  },
  computed: {
    /* 转树形数据 */
    optionData() {
      let cloneData = JSON.parse(JSON.stringify(this.list)); // 对源数据深度克隆
      return cloneData.filter(father => {
        // 循环所有项，并添加children属性
        let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
        branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性，并赋值
        return father.parentId == 0; //返回第一层
      });
    }
  },
  mounted() {
    //活动id
    //0-创建-1-编辑；
    this.auth = this.$route.query.auth;
    this.active = this.$route.query.active;
    //根据当前url中active参数判断执行第几步方法
    this.nextOrBack();
    //
    //
  }
};
</script>

<style scoped lang="scss">
@import '../../../assets/css/public.scss';
/deep/ .is-bordered{
  padding: 12px 20px 12px 10px;
}
.mleft10 {
  margin-right: 10px;
}
.vt {
  /deep/ .el-form-item__content {
    vertical-align: top !important;
  }
}
.create_stepOne
  .disCountSet.disCountSetTwo
  .el-form-item
  /deep/
  .el-form-item__content
  .el-input
  .el-input__inner {
  width: 80px;
}
.create_stepOne
  .disCountSet.disCountSetTwo
  .el-form-item
  /deep/
  .el-form-item__content
  .el-input {
  width: auto;
}
.specialTable {
  /deep/ .el-table__body tr,
  .el-table__body td {
    height: 100px !important;
  }
  /deep/ .el-table__row {
    td {
      .cell {
        text-overflow: ellipsis;
        // display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        max-height: 70px;
        overflow: visible !important;
      }
    }
  }
}
.errorInfoAlignment{
  /deep/ .el-form-item__error{
    left: 35px !important;
  }
}
/deep/ .w72{
  width: 72px !important;
  .el-input__inner{
    width: 72px !important;
  }
}
.labelAlignmentSpecial{
  /deep/ .el-form-item__content{
    line-height: 32px !important;
  }
}
.flexBox{
  display: flex;
  flex-wrap: nowrap;
  align-content: flex-start;
  .child-name{
    flex-shrink: 0;
  }
  .checkboxes{
    display: flex;

  }

}

.w126{
  width: 126px;
}
.oe{
  overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
}
.width100{
  width: 97px;
}
.w104{
  width: 104px;
}
.ml60{
  margin-left: 60px;
}
.pdl30{
  padding-left: 30px;
}
.pdt20{
  padding-top: 20px;
}
.w315{
  width: 315px !important;
}
.w138{
  width:138px !important ;
}
.width450{
  width: 450px !important;
  /deep/ .el-input__inner{
    width:450px !important;
  }
}
</style>
